Knowledge Center

Knowledge Center > Commerce > Zuora for Salesforce Development Resources > Zuora for Salesforce Component Library > Zuora for Salesforce Global Components > CreateQuote Component > Populate Value Plugin Example

Populate Value Plugin Example

This article describes the process of implementing a custom plug-in by extending the standard IPopulateValuePlugin plug-in of the CreateQuote component.

For additional sample plugin and a test class example, see  Zuora for Salesforce Sample Code Suite.

Implement a Populate Default Field Value Plugin

You have an option to extend the component plugin Instead of overriding a plugin. You can only extend a plugin that is defined as virtual. When you extend a plugin, you enhance the behavior of a component by adding your custom logic on top of the existing logic.

When you extend a virtual class, use the super keyword to override constructors and methods from the parent class.

In this example, you will modify the IPopulateValuePlugin of the CreateQuote component to provide the default quote values that are relevant to your subscription model. 

Use the following plugin implementation in this example.

global class DefaultValues extends zqu.CreateQuoteController.PopulateDefaultFieldValuePlugin{  
   global override void populateDefaultFieldValue
​      (SObject record, zqu.PropertyComponentController.ParentController pcc)
   {    
      super.populateDefaultFieldValue(record, pcc);  
      
      //Populate default values in the quote header  
      record.put('zqu__InitialTerm__c', 15);    
      record.put('zqu__RenewalTerm__c', 12);    
      record.put('zqu__ValidUntil__c', Date.today().addDays(30));    
      record.put('zqu__StartDate__c', Date.today());    
      record.put('zqu__PaymentMethod__c', 'Check');  
      
      // Retrieve the account ID from the quote         
      Id accountId = (Id) record.get('zqu__Account__c');         
      
      // Find the contacts associated with the account         
      List<Contact>contacts = [SELECT Id, Name FROM Contact WHERE Account.Id = :accountId];         
      
      // Assuming the contacts are present set the billTo and soldTo to the first contact         
      if  (contacts.size() > 0) {             
         // System.debug('mp: about to add ' + contacts[0].Id + ' as a contact ID');             
         record.put('zqu__BillToContact__c', contacts[0].Id);             
         record.put('zqu__SoldToContact__c', contacts[0].Id);             
      
         // Beforeretrieving  the lookup  options, needs to populate the map first             
         super.setLookupOptions(pcc);             
      
         // Now retrieve the lookup component options             
         zqu.LookupComponentOptions billToOptions = super.getLookupOption('zqu__BillToContact__c');             
         billToOptions.targetId = contacts[0].Id;             
         billToOptions.targetName = contacts[0].Name;             
         zqu.LookupComponentOptions soldToOptions  = super.getLookupOption('zqu__SoldToContact__c');             
         soldToOptions.targetId = contacts[0].Id;             
         soldToOptions.targetName = contacts[0].Name;         
      }
   }
}  

To extend the IPopulateValuePlugin for the CreateQuote property component:

  1. Extend the plugin by creating a new class using the above code.
  2. Navigate to Zuora Config > Component Registration.
  3. On the Component Registration page, click Edit for the CreateQuote component.
  4. In the Update component section, the plugins for the component are listed. The IPopulateValuePlugin plugin is extendible as the Can Be Extended field is checked.
  5. Create the custom plugin, named DefaultValues, by extending the default class of the IPopulateValuePlugin. Use the implementation sample shown above.
  6. On the Component Registration page, enter the new plugin class name, DefaultValues, in the Class Name field for the IPopulateValuePlugin of the CreateQuote property component.
    DefaultValuesPlugin.png
  7. Click Update, and the updated default values are immediately applied to the Create Quote process.
Last modified
15:44, 12 Aug 2015

Tags

This page has no custom tags.

Classifications

(not set)