Use Case
When creating a quote or an order, sometimes the selectable products can be different under different conditions.
For example, the available products may be restricted or limited for different channel sales. To support this case, you can add a Product Search Plugin to implement the business logic via Salesforce Apex code.
Implement Product Search Plugin Interface
Create an Apex class and implement the product search interface:
Ruby.CustomPluginManager.ProductSearchPlugin
The plugin returns a string containing SOQL query conditions, which will be appended to the query when searching for products in the LIne Editor.
Note : The apex class must be declared as ‘global’ since the interface is a global interface
Please see an example below:
/**
* An example Product Selector Plugin that returns different sets of products by sales channel.
*/
global class ProductSearchAdditionalFilterPlugin implements Ruby.CustomPluginManager.ProductSearchPlugin {
global String getAdditionalSearchFilters(){
// Get current object id
ID currentObjectId = Ruby.CustomPluginManager.getObjectId();
// Check whether the object is Quote
if(Schema.Quote.sObjectType == currentObjectId.getSobjectType()){
Quote quote = [Select Id, Name, Opportunity.RecordType.Name From Quote Where id =: currentObjectId];
String additionalFilter = '';
if(quote.Opportunity.RecordType.Name == 'Channel'){
additionalFilter = '(Product_Type__c = '+ '\'Channel\'' + ' OR Product_Type__c = NULL)';
}
return additionalFilter;
}
else{
return '';
}
}
}
Register the Plugin
Login to your Salesforce Org and navigate to Setup.
- Search for ‘Custom Setting’ and navigate to the Custom Settings list page.
- Click on the ‘Manage’ link on ‘Nue System Setting’
- Search for ‘ProductSearchPlugin’ and click ‘Edit’
- In the edit page, add your Apex class name to the value field and save the change
Now in the Line Editor for both quotes and orders, the plugin will be executed when users search for products.