Skip to content

Commit d73b804

Browse files
committed
Update the README; Renamed the Class TestDataSetup.cls as ExtededTestDataSetup for compatibility; Fix the issue that block resuing MasterQuote to generate Sub Quotes/Subscriptions.
1 parent 587e164 commit d73b804

File tree

6 files changed

+63
-55
lines changed

6 files changed

+63
-55
lines changed

QuoteSplit/README

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,18 @@ INTRODUCTION
3131

3232
This Z-Force Sample Code package provides a reference implementation that split single Quote(MasterQuote) into two Quotes(SubQuote) and sending to Z-Billing.
3333

34+
USE CASES
35+
---------
36+
a. The customers have two categories of Rate Plans ("Regular" and "Power") that need to send to Z-Billing according to the categories but to track using one Quote on SFDC called MasterQuote.
37+
b. Correspondingly to the two categories, there could be two SubQuotes. In this sample code, we can send two SubQuotes simultaneously to Z-Billing (only if there are two different categories of Rate Plans selected for the Quote),
38+
and there will be two Subscriptions generated after sending to Z-Billing.
39+
c. The Subscription(s) will generated on single existing Billing Account;
40+
d. The Subscription Zuora ID(s) will be written back to the SubQuote(s) then roll up to the MasterQuote, among which, the "Regular" Subscription's ID will be stored in MasterQuote's zqu__ZuoraSubscriptionID__c,
41+
and the "Power" Subscription's ID will be stored in the MasterQuotes' Extended_Zuora_Subscription_ID__c.
42+
e. The SubQuote(s) will be deleted after subscribing, and only MasterQuote will be persisted.
3443

3544
PRE-REQUISITES
3645
-------------
37-
3846
1. This sample code package is an unmanaged package that depends on the following Z-Force managed packages:
3947
- Z-Force 360 Version 2.3
4048
- Z-Force Quotes Version 5.5
@@ -65,17 +73,17 @@ ant deploy
6573

6674
This will deploy the sample code unmanaged package into your Salesforce.com organization.
6775

68-
6976
And the second approach is by installation:
7077

7178
1. Install this sample code package using the following Force.com Installation URL:
7279

73-
https://login.salesforce.com/packaging/installPackage.apexp?p0=04tE0000000HPlS
80+
Z-Quotes Quote Split V 1.3
81+
https://login.salesforce.com/packaging/installPackage.apexp?p0=04tE0000000HQcY
7482

7583
This will install sample code unmanaged package into your Salesforce.com organization.
7684

7785
PACKAGE CONTENTS
78-
================
86+
----------------
7987

8088
Fields (3)
8189
Component Name Parent Object Component Type Description
@@ -88,7 +96,7 @@ Code (3)
8896
Component Name Parent Object Component Type Description
8997
ExtendedZQuoteUtil Apex Class The reference implementation that split single Quote(MasterQuote) into two Quotes(SubQuote) and sending to Z-Billing.
9098
SendToZBillingPreviewController Apex Class The entry page' controller which is to call ExtendedZQuoteUtil.sendToZBilling.
91-
TestDataSetup Apex Class Setup test data for apex unit test.
99+
ExtendedTestDataSetup Apex Class Setup test data for apex unit test.
92100

93101
Pages (1)
94102
Component Name Parent Object Component Type Description
@@ -98,3 +106,16 @@ SendToZBillingPreview
98106
Resources (1)
99107
Component Name Parent Object Component Type Description
100108
Send to Z-Billing (Quote Split) Quote Button or Link The link to SendToZBillingPreview page.
109+
110+
OPERATION MANUAL
111+
---------------
112+
1. Sync the product catalog from Z-Billing as usual, then check the Product Rate Plans, choose part of the records and set the Category__c field on the records.
113+
Currently we support two categories "Power" or "Regular";
114+
2. Create an Opportunity;
115+
3. On the Opportunity, create a New Subscription Quote as MasterQuote and select products, either from "Power" or "Regular" category, for that Quote,
116+
in another word, you can choose Product Rate Plans which belong to different Categories for the MasterQuote;
117+
4. In the Quote Detail page, click "Send to Z-Billing(Quote Split)" button to enter the SendToZBillingPreview page;
118+
5. In the SendToZBillingPreview, choose an existing Billing Account in Z-Billing(If there's no existing Billing Account, please prepare at least one in Z-Billing System).
119+
6. Click Button "Send to Z-Billing" to complete subscribe call.
120+
7. After that, you can verify the result in both SFDC and Z-Billing. In SFDC, the Quote object's zqu__ZuoraSubscriptionID__c or Extended_Zuora_Subscription_ID__c (or Both) should be populated with the Subscription ID(s) of SubQuote(s).
121+
And In Z-Billing, the corresponding Subscription record(s) should be generated already.

QuoteSplit/src/classes/TestDataSetup.cls renamed to QuoteSplit/src/classes/ExtendedTestDataSetup.cls

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@isTest
2-
public with sharing class TestDataSetup {
2+
public with sharing class ExtendedTestDataSetup {
33

44
public static final String OPPORTUNITY_NAME = 'test opp';
55
public static final Boolean DEFAULT_ALLOW_UPDATE_BILL_CYCLE_DAY = false;
@@ -159,7 +159,7 @@ public with sharing class TestDataSetup {
159159
try {
160160
insert zprod;
161161
} catch (Exception e) {
162-
System.assert(false, 'TestDataSetup.prepareProductCatalog: Exception occured while inserting ZProduct__c. Exception Details: ' + e.getMessage());
162+
System.assert(false, 'ExtendedTestDataSetup.prepareProductCatalog: Exception occured while inserting ZProduct__c. Exception Details: ' + e.getMessage());
163163
}
164164
System.assert(null != zprod.Id, 'Product record preparation failed when prepare for testing product catalog.');
165165

@@ -183,7 +183,7 @@ public with sharing class TestDataSetup {
183183
try {
184184
insert p_rateplans;
185185
} catch (Exception e) {
186-
System.assert(false, 'TestDataSetup.prepareProductCatalog: Exception occured while inserting ProductRatePlan__c records. Exception Details: ' + e.getMessage());
186+
System.assert(false, 'ExtendedTestDataSetup.prepareProductCatalog: Exception occured while inserting ProductRatePlan__c records. Exception Details: ' + e.getMessage());
187187
}
188188
System.assert(p_rateplans.size() > 0, 'Product Rateplan records prepare failed when prepare for testing product catalog.');
189189
List < zqu__ProductRatePlanCharge__c > p_all_charges = new List < zqu__ProductRatePlanCharge__c > ();
@@ -194,7 +194,7 @@ public with sharing class TestDataSetup {
194194
try {
195195
insert p_all_charges;
196196
} catch (Exception e) {
197-
System.assert(false, 'TestDataSetup.prepareProductCatalog: Exception occured while inserting ProductRatePlanCharge__c records. Exception Details: ' + e.getMessage());
197+
System.assert(false, 'ExtendedTestDataSetup.prepareProductCatalog: Exception occured while inserting ProductRatePlanCharge__c records. Exception Details: ' + e.getMessage());
198198
}
199199
System.assert(p_all_charges.size() > 0, 'Product Rateplan charge records prepare failed when prepare for testing product catalog.');
200200
List < zqu__ProductRatePlanChargeTier__c > p_all_tiers = new List < zqu__ProductRatePlanChargeTier__c > ();
@@ -205,7 +205,7 @@ public with sharing class TestDataSetup {
205205
try {
206206
insert p_all_tiers;
207207
} catch (Exception e) {
208-
System.assert(false, 'TestDataSetup.prepareProductCatalog: Exception occured while inserting ProductRatePlanChargeTier__c records. Exception Details: ' + e.getMessage());
208+
System.assert(false, 'ExtendedTestDataSetup.prepareProductCatalog: Exception occured while inserting ProductRatePlanChargeTier__c records. Exception Details: ' + e.getMessage());
209209
}
210210
System.assert(p_all_tiers.size() > 0, 'Product Rateplan charge tier records prepare failed when prepare for testing product catalog.');
211211
}
@@ -296,7 +296,7 @@ public with sharing class TestDataSetup {
296296
try {
297297
insert acc;
298298
} catch (Exception e) {
299-
System.assert(false, 'TestDataSetup.prepareTestQuote: Exception occured while inserting Account record. Exception Details: ' + e.getMessage());
299+
System.assert(false, 'ExtendedTestDataSetup.prepareTestQuote: Exception occured while inserting Account record. Exception Details: ' + e.getMessage());
300300
}
301301
System.assert(null != acc.Id, 'Apex Test Failed to create Mockup account.');
302302

@@ -307,7 +307,7 @@ public with sharing class TestDataSetup {
307307
try {
308308
insert billto;
309309
} catch (Exception e) {
310-
System.assert(false, 'TestDataSetup.prepareTestQuote: Exception occured while inserting Bill To Contact record. Exception Details: ' + e.getMessage());
310+
System.assert(false, 'ExtendedTestDataSetup.prepareTestQuote: Exception occured while inserting Bill To Contact record. Exception Details: ' + e.getMessage());
311311
}
312312
System.assert(null != billto.Id, 'Apex Test failed to create Mockup Bill To Contact.');
313313

@@ -318,7 +318,7 @@ public with sharing class TestDataSetup {
318318
try {
319319
insert soldto;
320320
} catch (Exception e) {
321-
System.assert(false, 'TestDataSetup.prepareTestQuote: Exception occured while inserting Sold To Contact record. Exception Details: ' + e.getMessage());
321+
System.assert(false, 'ExtendedTestDataSetup.prepareTestQuote: Exception occured while inserting Sold To Contact record. Exception Details: ' + e.getMessage());
322322
}
323323
System.assert(null != soldto.Id, 'Apex Test failed to create Mockup Sold To Contact.');
324324

@@ -330,7 +330,7 @@ public with sharing class TestDataSetup {
330330
try {
331331
insert opp;
332332
} catch (Exception e) {
333-
System.assert(false, 'TestDataSetup.prepareTestQuote: Exception occured while inserting Opportunity record. Exception Details: ' + e.getMessage());
333+
System.assert(false, 'ExtendedTestDataSetup.prepareTestQuote: Exception occured while inserting Opportunity record. Exception Details: ' + e.getMessage());
334334
}
335335
System.assert(null != opp.Id, 'The Insert Opportunity should not be null.');
336336
System.assert(null != opp.AccountId, 'The Insert Opportunity.AccountId should not be null.');
@@ -354,7 +354,7 @@ public with sharing class TestDataSetup {
354354
try {
355355
insert quote;
356356
} catch (Exception e) {
357-
System.assert(false, 'TestDataSetup.prepareTestQuote: Exception occured while inserting Quote record. Exception Details: ' + e.getMessage());
357+
System.assert(false, 'ExtendedTestDataSetup.prepareTestQuote: Exception occured while inserting Quote record. Exception Details: ' + e.getMessage());
358358
}
359359
System.assert(null != quote.Id, 'The Insert Quote should not be null.');
360360

@@ -382,10 +382,10 @@ public with sharing class TestDataSetup {
382382
quoteCharges.add(quoteCharge);
383383
}
384384
try {
385-
insert quoteCharges;
386-
} catch (Exception e) {
387-
System.assert(false, 'TestDataSetup.prepareTestQuote: Exception occured while inserting QuoteCharge record. Exception Details: ' + e.getMessage());
388-
}
385+
insert quoteCharges;
386+
} catch (Exception e) {
387+
System.assert(false, 'ExtendedTestDataSetup.prepareTestQuote: Exception occured while inserting QuoteCharge record. Exception Details: ' + e.getMessage());
388+
}
389389
}
390390

391391
return quote;

QuoteSplit/src/classes/TestDataSetup.cls-meta.xml renamed to QuoteSplit/src/classes/ExtendedTestDataSetup.cls-meta.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<apiVersion>23.0</apiVersion>
44
<packageVersions>
55
<majorNumber>5</majorNumber>
6-
<minorNumber>3</minorNumber>
6+
<minorNumber>5</minorNumber>
77
<namespace>zqu</namespace>
88
</packageVersions>
99
<status>Active</status>

QuoteSplit/src/classes/ExtendedZQuoteUtil.cls

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Sample code of spliting single Quote(MasterQuote) into two Quotes(SubQuote) and sending to Z-Billing.
2+
* Sample code of splitting single Quote(MasterQuote) into two Quotes(SubQuote) and sending to Z-Billing.
33
*
44
* User case
55
* a. The customers have two categories of Rate Plans (e.g. Regular/Power) that need to send to Z-Billing according to the categories but track using one MasterQuote.
@@ -39,8 +39,8 @@ global Class ExtendedZQuoteUtil {
3939

4040
// Create two Quotes, one for "Regular" Quote, and another for "Power" Quote.
4141
String subscribeDate = String.valueOf(System.now());
42-
final zqu__Quote__c regularQuote = generateSubQuote(masterQuote, '[Regular]', subscribeDate);
43-
final zqu__Quote__c powerQuote = generateSubQuote(masterQuote, '[Power]', subscribeDate);
42+
final zqu__Quote__c regularQuote = generateSubQuote(masterQuote, CATEGORY_REGULAR, subscribeDate);
43+
final zqu__Quote__c powerQuote = generateSubQuote(masterQuote, CATEGORY_POWER, subscribeDate);
4444

4545
// Split the MasterQuote as two SubQuotes.
4646
splitQuote(masterQuote, regularQuote, powerQuote);
@@ -93,13 +93,20 @@ global Class ExtendedZQuoteUtil {
9393
/**
9494
* Generate SubQuote.
9595
*/
96-
private static zqu__Quote__c generateSubQuote(zqu__Quote__c masterQuote, String namePrefix, String nameSurfix) {
96+
private static zqu__Quote__c generateSubQuote(zqu__Quote__c masterQuote, String category, String timeStamp) {
9797
zqu__Quote__c subQuote = masterQuote.clone();
98-
subQuote.Name = namePrefix + ' ' + masterQuote.Name + ' ' + nameSurfix;
99-
// Set the look-up key to MasterQuote__c, if customer want to support sending SubQuotes seperately,
100-
// and update MasterQuote seperately, then the MasterQuote__c will be used.
101-
subQuote.MasterQuote__c = masterQuote.id;
102-
subQuote.zqu__Opportunity__c = masterQuote.zqu__Opportunity__c;
98+
// Initialize the SubQuote.
99+
{
100+
subQuote.Extended_Zuora_Subscription_ID__c = null;
101+
subQuote.zqu__ZuoraSubscriptionID__c = null;
102+
subQuote.Name = '[' + category + ']' + ' ' + masterQuote.Name + ' ' + timeStamp;
103+
subQUote.zqu__Description__c = subQuote.Name;
104+
105+
// Set the look-up key to MasterQuote__c, if customer want to support sending SubQuotes seperately,
106+
// and update MasterQuote seperately, then the MasterQuote__c will be used.
107+
subQuote.MasterQuote__c = masterQuote.id;
108+
subQuote.zqu__Opportunity__c = masterQuote.zqu__Opportunity__c;
109+
}
103110
insert subQuote;
104111
return subQuote;
105112
}
@@ -170,7 +177,7 @@ global Class ExtendedZQuoteUtil {
170177
* Unit Test.
171178
*/@isTest
172179
private static void splitQuoteTest() {
173-
final zqu__Quote__c masterQuote = TestDataSetup.getQuote();
180+
final zqu__Quote__c masterQuote = ExtendedTestDataSetup.getQuote();
174181

175182
String subscribeDate = String.valueOf(System.now());
176183
final zqu__Quote__c regularQuote = ExtendedZQuoteUtil.generateSubQuote(masterQuote, '[Regular]', subscribeDate);
@@ -180,18 +187,18 @@ global Class ExtendedZQuoteUtil {
180187

181188
final List < zqu__QuoteCharge__c > regularQuoteCharges = [SELECT zqu__Quote__c, zqu__ProductRatePlanName__c FROM zqu__QuoteCharge__c WHERE zqu__Quote__c = : regularQuote.id];
182189
for (zqu__QuoteCharge__c regularQuoteCharge: regularQuoteCharges) {
183-
System.assertEquals(CATEGORY_REGULAR, TestDataSetup.PLAN_NAME_CATEGORY_MAPPING.get(regularQuoteCharge.zqu__ProductRatePlanName__c));
190+
System.assertEquals(CATEGORY_REGULAR, ExtendedTestDataSetup.PLAN_NAME_CATEGORY_MAPPING.get(regularQuoteCharge.zqu__ProductRatePlanName__c));
184191
}
185192

186193
final List < zqu__QuoteCharge__c > powerQuoteCharges = [SELECT zqu__Quote__c, zqu__ProductRatePlanName__c FROM zqu__QuoteCharge__c WHERE zqu__Quote__c = : powerQuote.id];
187194
for (zqu__QuoteCharge__c powerQuoteCharge: powerQuoteCharges) {
188-
System.assertEquals(CATEGORY_POWER, TestDataSetup.PLAN_NAME_CATEGORY_MAPPING.get(powerQuoteCharge.zqu__ProductRatePlanName__c));
195+
System.assertEquals(CATEGORY_POWER, ExtendedTestDataSetup.PLAN_NAME_CATEGORY_MAPPING.get(powerQuoteCharge.zqu__ProductRatePlanName__c));
189196
}
190197
}
191198

192199
@isTest
193200
private static void doSendCodeCoverageTest() {
194-
final zqu__Quote__c masterQuote = TestDataSetup.getQuote();
201+
final zqu__Quote__c masterQuote = ExtendedTestDataSetup.getQuote();
195202

196203
String subscribeDate = String.valueOf(System.now());
197204
final zqu__Quote__c regularQuote = generateSubQuote(masterQuote, '[Regular]', subscribeDate);

QuoteSplit/src/classes/SendToZBillingPreviewController.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public with sharing class SendToZBillingPreviewController {
116116
*/
117117
@isTest
118118
private static void pageControllerCodeCaverageTest() {
119-
final zqu__Quote__c masterQuote = TestDataSetup.getQuote();
119+
final zqu__Quote__c masterQuote = ExtendedTestDataSetup.getQuote();
120120
SendToZBillingPreviewController pageController = new SendToZBillingPreviewController(new ApexPages.StandardController(masterQuote));
121121
pageController.doSend();
122122
}

QuoteSplit/src/package.xml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
33
<fullName>Z-Quotes Quote Split</fullName>
4-
<description>Sample code of spliting single Quote(MasterQuote) into two Quotes(SubQuote) and sending to Z-Billing.</description>
5-
<types>
6-
<members>ExtendedZQuoteUtil</members>
7-
<members>SendToZBillingPreviewController</members>
8-
<members>TestDataSetup</members>
9-
<name>ApexClass</name>
10-
</types>
11-
<types>
12-
<members>SendToZBillingPreview</members>
13-
<name>ApexPage</name>
14-
</types>
15-
<types>
16-
<members>zqu__ProductRatePlan__c.Category__c</members>
17-
<members>zqu__Quote__c.Extended_Zuora_Subscription_ID__c</members>
18-
<members>zqu__Quote__c.MasterQuote__c</members>
19-
<name>CustomField</name>
20-
</types>
21-
<types>
22-
<members>zqu__Quote__c.Send_to_Z_Billing_Quote_Split</members>
23-
<name>WebLink</name>
24-
</types>
4+
<description>Sample code of splitting single Quote(MasterQuote) into two Quotes(SubQuote) and sending to Z-Billing.</description>
255
<version>21.0</version>
266
</Package>

0 commit comments

Comments
 (0)