Save Rate Plan Plugin Example
This article describes the process of creating a sample custom Save Rate Plan Plugin on the SelectProduct component. The sample plugin does the following:
- Detect and print the numbers of added, removed, updated, and unedited charge groups.
- Validate if new charge groups were added on save.
Implement the Save Rate Plan Plugin
Follow these steps to set up the product catalog, create a plugin, and test the plugin.
To set up rate plans and the association between the rate plans:
- In your Zuora Product Catalog, add a product and a rate plan. Name the rate plan "SomeSampleRatePlan".
- Perform a Product Catalog Sync.
To create the plugin class and register the new plugin for the SelectProduct component:
- In Salesforce, create a new class, SampleImplementationForOnSavePlugin, using the code below.
- Navigate to Zuora Config > Component Registration.
- Click Edit for the SelectProduct component.
- In the Component Plugins section, for the Save Rate Plan Plugin type, specify SampleImplementationForOnSavePlugin in the Class Name field and click Update.
To test the newly added plugin:
- To test the new plug-in, add the Product and its rate plan, SomeSampleRatePlan, to a quote.
- When you click Save in the Product Selector, you will see the following error message:
'You are not allowed to add new rate plans to this Quote.'
The following is a code for the sample plugin:
global class SampleImplementationForOnSavePlugin implements zqu.SelectProductComponentOptions.ISaveRatePlanPlugin { public void onSave(List<zqu.zChargeGroup> addedChargeGroups, List<zqu.zChargeGroup> updatedChargeGroups, List<zqu.zChargeGroup> removedChargeGroups, List<zqu.zChargeGroup> persistedChargeGroups){ System.debug('zuora - SampleImplementationForOnSavePlugin - onSave executed'); System.debug('zuora - SampleImplementationForOnSavePlugin - addedChargeGroups.size() : ' + addedChargeGroups.size()); System.debug('zuora - SampleImplementationForOnSavePlugin - updatedChargeGroups.size() : ' + updatedChargeGroups.size()); System.debug('zuora - SampleImplementationForOnSavePlugin - removedChargeGroups.size() : ' + removedChargeGroups.size()); System.debug('zuora - SampleImplementationForOnSavePlugin - persistedChargeGroups.size() : ' + persistedChargeGroups.size()); // Validate addedChargeGroups if(addedChargeGroups.size() > 0){ throw new SavePluginException('You are not allowed to add new rate plans to this Quote.'); } } global class SavePluginException extends Exception {} }