Guided Selling Flow Plugin Example
This article describes the process of creating a sample custom Guided Selling Flow Plugin on the SelectProduct component. The sample plug-in displays the corresponding Guided Selling Flows based on the quote type, New Subscription or Amendment/Renewal.
Implement a Guided Selling Flow Plugin
To create a new plugin and register:
- Navigate to Zuora Config > Guided Product Selectors.
- Create Guided Selling Flows, New Service Flow and Amend Service Flow. Save the flows.
- Create a new class, GuidedSellingFlowPluginImpl, using the code below.
- Navigate to Zuora Config > Component Registration.
- Click Edit for the SelectProduct component.
- In the Component Plugins section, for the Guided Selling Flow Plugin type, specify GuidedSellingFlowPluginImpl in the Class Name field.
- Click Update.
To test the new plug-in:
- Create a quote for New Subscription.
- When you get to the Choose Product and Charges step, you see the Guided Selling Flows whose label starts with "New".
global class GuidedSellingFlowPluginImpl implements
zqu.SelectProductComponentOptions.IGuidedSellingFlowPlugin{
public List<ID> getFlows(Id quoteId){
List < Id > flowIds = new List < Id >();
if(String.isBlank(quoteId)) return flowIds;
// Retrieve the quote based on Id
List < zqu__Quote__c > quoteList = [SELECT Name, zqu__SubscriptionType__c
FROM zqu__Quote__c WHERE Id = :quoteId];
if(quoteList.isEmpty()) return flowIds;
// Determine the string to query flows based on the subscription type of the
quote
String flowName = quoteList[0].zqu__SubscriptionType__c == 'New Subscription'
? 'New %' : '%Amend%"';
// Query for flows based on the name and IncludeInProductSelector flag
List < zqu__GuidedSellingFlow__c > flows = [SELECT Id FROM
zqu__GuidedSellingFlow__c WHERE zqu__IncludeInProductSelector__c = true AND (Name
like :flowName)];
if(flows.isEmpty()) return flowIds;
// If flows were found, add their ids to the result list
for(zqu__GuidedSellingFlow__c flow : flows) {
flowIds.add(flow.Id);
}
return flowIds;
}
}
Test Class for Guided Selling Flow Plugin
The following is a APEX test class code sample for Guided Selling Flow Plugin. You can use the test class to achieve code coverage on the plugin in Salesforce.
@isTest
public class GuidedSellingFlowPluginImplTest {
@isTest
static void testGetFlows() {
Account acc = new Account(name='Test Account');
insert acc;
Contact billTo = new Contact(FirstName = 'BillToFName', LastName =
'BillToLName');
billTo.accountId = acc.Id;
Contact soldTo = new Contact(FirstName = 'SoldToFName', LastName =
'SoldToLName');
soldTo.accountId = acc.Id;
Contact[] contacts = new List<Contact>{ billTo, soldTo };
insert contacts;
zqu__Quote__c quote = new zqu__Quote__c();
quote.Name = 'test quote';
quote.zqu__Account__c = acc.Id;
quote.zqu__SubscriptionType__c = 'New Subscription';
insert quote;
zqu__GuidedSellingFlow__c flow = new zqu__GuidedSellingFlow__c();
flow.Name = 'New Flow';
flow.zqu__IncludeInProductSelector__c = true;
insert flow;
GuidedSellingFlowPluginImpl gsfp = new GuidedSellingFlowPluginImpl();
gsfp.getFlows(quote.Id);
}
}
