Use Cases
When creating a quote, the default values of the quote fields may be different for different scenarios. For example, the quote template is determined by the account type, channel sales have a different quote template from the direct sales. To support this case, you can add a default value plugin to implement the business logic via Salesforce Apex code.
Implement Plugin Interface
Create an Apex class and implement the quote default value plugin interface :
Ruby.CustomPluginManager.CreateQuoteDefaultValuePlugin
The plugin returns the quote object which will be used to populate the default values on quote creation page.
Note : The apex class must be declared as ‘global’ since the interface is a global interface |
In the following plugin example, the Quote Template field will be automatically populated based on the Account Record Type.
global class CreateQuoteDefaultValuePlugin implements Ruby.CustomPluginManager.CreateQuoteDefaultValuePlugin{
global Quote getDefaultValues(Quote newQuote){
System.debug('newQuote : ' + newQuote);
// Build quote template map
Map<String, Id> templateMap = new Map<String, Id>();
List<Quote> quoteTemplates = [Select Id, Name From Quote Where Ruby__Is_Template_Quote__c = true];
for(Quote template : quoteTemplates){
if(template.Name == 'Quote Template for Channel Sales'){
templateMap.put('channel', template.Id);
}
else if(template.Name == 'Quote Template for Direct Sales'){
templateMap.put('sales', template.Id);
}
}
// Get quote related account info
Account acct = [SELECT Id, Name, RecordType.Name FROM Account WHERE Id = :newQuote.accountId];
if(relatedAccount != null){
// Default the quote template based on the related account record type
if(relatedAccount.RecordType.Name == 'Channel'){
newQuote.Ruby__Template_Quote__c = templateMap.get('channel');
}
else{
newQuote.Ruby__Template_Quote__c = templateMap.get('sales');
}
}
//Default the shipping and billing addresses to the shipping and billing addresses of the billing account associated
Account billingAcct;
Account[] billingAccounts =
[SELECT Id, Name,
BillingStreet, BillingCity, BillingState, BillingCountry, BillingPostalCode,
ShippingStreet, ShippingCity, ShippingState, ShippingCountry, ShippingPostalCode
FROM Account
WHERE Ruby__SalesAccount__c = :newQuote.accountId];
if ( billingAccounts.size() > 0 ) {
billingAcct = billingAccounts[0];
newQuote.Ruby__IsShippingAddressSameAsBilling__c = false;
newQuote.ShippingStreet = billingAcct.ShippingStreet;
newQuote.ShippingCity = billingAcct.ShippingCity;
newQuote.ShippingState = billingAcct.ShippingState;
newQuote.ShippingCountry = billingAcct.ShippingCountry;
newQuote.ShippingPostalCode = billingAcct.BillingPostalCode;
newQuote.BillingStreet = billingAcct.BillingStreet;
newQuote.BillingCity = billingAcct.BillingCity;
newQuote.BillingState = billingAcct.BillingState;
newQuote.BillingCountry = billingAcct.Billingcountry;
newQuote.BillingPostalCode = billingAcct.BillingPostalCode;
}
else {
System.debug('This account has no billing accounts associated');
}
return newQuote;
}
}
Register Plugin
Login to your Salesforce org and in the system setting page :
- Search for ‘Custom Setting’ and go to the custom setting list page
- Click on the ‘Manage’ link on ‘Nue System Setting’
- Search for ‘CreateQuoteDefaultValuePlugin’ and click ‘Edit’
- In the edit page, add your apex class name to the value field and save the change
Now on the Create Quote page, the plugin will be executed before the page gets loaded, and all the fields’ values will be pre-populated automatically.
Additional Notes
The address type field is not supported for this plugin prior to release 2402.