Set Default Price Book and Get Prices
You can use a Groovy script to set the default price book on an opportunity and get the latest prices onto the price book. The default price book can be set based on various opportunity attributes.
These opportunity attributes can be, for example, currency, customer geography, or customer account.
Here's how to set a default account price book on an opportunity.
Note that this procedure also sets a default Corporate price book on an opportunity, if an account price book can't be found.
-
Ensure you're working in an active sandbox.
-
In Application Composer, navigate to
. -
Select the Triggers tab.
-
Select the Add a New Trigger icon.
-
In the Trigger field, select Before Insert in Database.
-
In the Trigger Name field, enter
SetPriceBook
. -
In the Trigger Definition region, enter this script:
//Fetch the Id of Account Pricebook def pricebookId = Organization?.PriceBook_Obj_c?.PricebookId; // Set the Id of Account PriceBook to Opty setAttribute('PriceBook_Id_c', pricebookId);
-
Click Save and Close.
-
Test the changes and publish the sandbox.
def accountplist=Organization?.getAttribute('PriceBook_c')
def optyplist=getAttribute('PriceBook_c')
if (optyplist == null ) {
if (accountplist == null ){
optyplist = 'Corporate' //This is the name of the default pricebook
}
setAttribute('PriceBook_c',accountplist)