Last Updated on May 7, 2022 by Rakesh Gupta
Big Idea or Enduring Question:
A Price Book is a book in which the prices of products are listed. Currently, business users have to select a price book as soon as an opportunity is created. In this article, let’s check out a way to auto-assign a Price book based on the Opportunity record type using the Salesforce Flow.
Objectives:
This blog post will help us to understand the following
- Using salesforce flow builder to auto-assign Price book when an opportunity is created, based on the opportunity record type.
- The opportunity object and create record types.
- The PriceBook object and creating price books
- Using Developer Console and SOQL query to find the PriceBookId
- How to use Custom Label in salesforce flow
Business Use case
Martin Jones is working as a System administrator at Universal Containers (UC). His organization wants to develop a Process to automate price book assignment based on the Opportunity record type and implement the following requirements.
- If the Opportunity record type is Manufacturing, then assign a price book Manufacturing
- If the Opportunity record type is Retail, then assign a price book Retail
Automation Champion Approach (I-do):
There are multiple possible solutions for the above business scenario. We will use Salesforce Flow to solve the above business requirement.
To solve this requirement, we will use the Before-save Record-Triggered Flow. Check out this article to understand why we are using before-save record-triggered flow for this scenario. Let’s breakdown the solution into the following steps for understanding:
- Create two opportunity record types – Manufacturing and Retail
- Create two Price books – Manufacturing and Retail
- Create a Salesforce Flow to automate the process of assigning the price book depending on the record type.
Before discussing it, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes going through the following Flow diagram and understand it. Let’s begin building this automation process.
Guided Practice (We-do):
There are 3 steps to solve Martin’s business requirement using Salesforce Flow. We must:
- Create two record types – Manufacturing and Retail
- Create two price books – Manufacturing and Retail
- Salesforce Flow
- Define Flow properties for record-triggered flow
- Add a Decision element to check the opportunity record type
- Add a Get Records element to find the retail price book record
- Add a Get Records element to find the manufacturing price book record
- Create a Formula to determine the pricebook2Id based on the record type
- Add an Assignment element to set pricebook2Id on the opportunity
Step 1: Create Two Record Types
- Click Setup.
- In the Object Manager, type Opportunity.
- Click on the Record Type, then click New.
- Name the Record Type Label and the Record Type Name will populate.
- Now select the Sales Process and make sure to select the Active checkbox.
- Click Save.
Step 2: Create Two Price Books
- Navigate to App Launcher and select the Price Books.
- Click on the New button.
- Name the Price Book and make sure to select the Active checkbox.
- Click Save.
Step 3.1: Salesforce Flow – Define Flow Properties
- Click Setup.
- In the Quick Find box, type Flows.
- Select Flows, then click on the New Flow.
- Select the Record-Triggered Flow option, click on Create and configure the flow as follows:
- Object: Opportunity
- Trigger the Flow When: A record is created or updated
- Set Entry Criteria
- Condition Requirements: None
- Optimize the Flow For Fast Field Updates
- Click Done.
Step 3.2: Salesforce Flow – Using Decision Element to Check Record Type
We will now use the Decision element to check the opportunity record type and identify if the record has been created or updated. Now follow the steps below:
- On Flow Designer, click on the + icon and select the Decision element.
- Enter a name in the Label field; the API Name will auto-populate.
- Under Outcome Details, enter the Label (Retail) the API Name will auto-populate.
- Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
- Under Outcome Details, click on the +
- Enter the Label (Manufacturing) the API Name will auto-populate.
- Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
- Row 1:
- Resource: {!$Record.Id}
- Operator: Is Null
- Value: {!$GlobalConstant.True}
- Add Condition
- Row 2:
- Resource: {!$Record.RecordTypeId}
- Operator: Equals
- Value: {!$GlobalConstant.False}
- Add Condition
- Row 3:
- Resource: {!$Record.RecordType.DeveloperName}
- Operator: Equals
- Value: Manufacturing
- Row 1:
Step 3.3: Salesforce Flow – Adding a Get Record Element to Find Retail Price Book Record
The next step is to get the retail price book record. Now follow the steps below:
- On Flow Designer, click on the + icon and select the Get Records element.
- Enter a name in the Label field; the API Name will auto-populate.
- Select the Price Book object from the dropdown list.
- Select All Conditions Are Met (AND).
- Set Filter Conditions
- Row 1:
- Field: Name
- Operator: Equals
- Value: Retail
- Row 1:
- How Many Records to Store:
- select Only the first record
- How to Store Record Data:
- Choose the option to Automatically store all fields.
- Click Done.
Step 3.4: Salesforce Flow – Adding a Get Record Element to Find Manufacturing Price Book Record
The next step is to get the manufacturing price book record. Now follow the steps below:
- On Flow Designer, click on the + icon and select the Get Records element.
- Enter a name in the Label field; the API Name will auto-populate.
- Select the Price Book object from the dropdown list.
- Select All Conditions Are Met (AND).
- Set Filter Conditions
- Row 1:
- Field: Name
- Operator: Equals
- Value: Manufacturing
- Row 1:
- How Many Records to Store:
- select Only the first record
- How to Store Record Data:
- Choose the option to store all fields Automatically.
- Click Done.
Step 3.5: Salesforce Flow – Formula to Determine the Pricebook2Id Based on the Opportunity Record Type
- Under Toolbox, select Manager, then click New Resource to construct the push notification title.
- Input the following information:
- Resource Type: Formula
- API Name: forT_PricebookId
- Data Type: Text
- Formula: IF({!$Record.RecordType.DeveloperName}=’Manufacturing’, {!Get_Manufacturing_Pricebook.Id},
IF({!$Record.RecordType.DeveloperName}=’Retail’,{!Get_Retail_Pricebook.Id},
{!$Record.Pricebook2Id}
))
- Click Done.
Step 3..6: Salesforce Flow – Using Assignment Element to Update PriceBook2Id on Opportunity
The next step is to update the pricebook2Id on the opportunity. We will use the Assignment element, as we are using before-save flow.
- Under Toolbox, select Element.
- Drag-and-drop Assignment element onto the Flow designer.
- Enter a name in the Label field; the API Name will auto-populate.
- Set Variable Value
- Row 1:
- Field: {!$Record.Pricebook2Id}
- Operator: Equals
- Value: {!forT_PricebookId}
- Field: {!$Record.Pricebook2Id}
- Row 1:
- Click Done.
In the end, Martin’s Flow will look like the following screenshot: Once everything looks good, perform the steps below:
- Click Save.
- Enter Flow Label the API Name will auto-populate.
- Click Show Advanced.
- API Version for Running the Flow: 54
- Interview Label: Record-Trigger: Record-Triggered Flow: Opportunity Before Save {!$Flow.CurrentDateTime}
- Click Save.
Almost there! Once everything looks good, click the Activate.
Proof of Concept
Now onwards, if a business user creates an Opportunity with any of these two record types, then Salesforce Flow will automatically add a corresponding price book to it.
- Create an Opportunity with record type Manufacturing, as shown in the following screenshot:
- Once you are done, check out the Product related list available on the Opportunity detail page.
Formative Assessment:
I want to hear from you!
What is one thing you learned from this post? How do you envision applying this new knowledge in the real world?
Let me know by Tweeting me at @automationchamp, or find me on LinkedIn.
The formula syntax is my error please provide the correct formula
Here you go:
IF({!$Record.RecordType.DeveloperName}=’Manufacturing’, {!Get_Manufacturing_Pricebook.Id},
IF({!$Record.RecordType.DeveloperName}=’Retail’,{!Get_Retail_Pricebook.Id},
{!$Record.Pricebook2Id}
))
Your guide has 2 mistakes – retail “is null” or “equals” / also the copy + paste formula does not work and leaves me with a syntax error.
It is a problem of copy-paste formulas from WordPress. Rewrite a single quote (‘) in the formula.
i dont what i am doing wrong in this scenerio followed staps as mentioned but having trouble , the error apears when i create a record : We can’t save this record because the “Auto assign pricebook based on opportunity record type” process failed. Give your Salesforce admin these details. This error occurred when the flow tried to update records: INVALID_CROSS_REFERENCE_KEY: invalid cross reference id. You can look up ExceptionCode values in the SOAP API Developer Guide. Error ID: 400282071-25548 (841704332)
Please send me complete error message or Developer Console Log
Great! Thanks a ton 🙂
Good luck with implementation, and let me know how it goes.
Hi Rakesh,
Is it possible to refer the pricebook name rather than ID? We update pricebooks pretty regularly and all of them have currency code in their names. I want to update the pricebook based on the quote currency using name instead of ID.
Thanks
Pratima
Yes, it is possible to use Pricebook name rather than ID.
–> First create a custom Label to store Pricebook Name
–> Now move your logic from Process Builder to Visual Workflow, I mean use Record Lookup element to find Pricebook ID based on Pricebook Name
–> At th end, use Record Update element to assign Pricebook to opportunity record.
Rakesh, I’ve followed your outline above to automatically add a Price Book to an Opportunity based upon the Opportunity Record Type – it works like a charm – thank you! I want to go a step further and also create a new (Opportunity) Product record based upon the Price Book that has been assigned; however, my process errors out. First, is this even possible within the same Process? Here’s a breakdown of what I’ve done:
– Followed your outline to add a Price Book to the Opportunity (this works great by itself)
– Created a second immediate action “Create a Record” for Record of “Opportunity Product”
– My Object Variables are:
— Opportunity ID / Reference / Opportunity.ID
— Quantity / Number / 1
— Sales Price / Currency / 0.00
— Type / Picklist / New Business
— Price Book Entry ID / ID / “18 Digit Price Book Entry ID”
Any ideas of how to make this work?
Thanks for your feedback! Can you please post the complete error message with screenshot of your process ? I think yes it’s possible with process builder.
Here you go
https://rakeshistom.files.wordpress.com/2015/07/craete-opportuntiy-poduct.png
Make sure that you have entered correct Price Book Entry Id for the Product
https://rakeshistom.files.wordpress.com/2015/07/pricebook-entry-id.png
Thank you! This looks like what I have tried – I would double check my Price Book Entry ID to make sure that is correct. Thanks!
🙂
Yes sorry, In my sandbox i’m still on version 33 and it only shows the Field and Value in the “set object veriable” , it looks like summer 15 added “type” in the variables section.
You can ignore the type field
Rakesh, I’m Learning so much with your process builder series of post! Thanks so much. I’m running into an issue though. I’d like to create a Price book entry in the standard price book when a product is created. I’d also like to update the standard price on that entry when a field I have called “GSA Price” is changed. It seemed like it would be an easy task but I keep getting “The record couldn’t be saved because it failed to trigger a flow” Error. Any chance you could help? Thanks, Chris
Can you please post me the snapshot of the debug log and Process Builder.
Screen Shots of each are at the link.
https://drive.google.com/folderview?id=0B-eUYDYy6F8yWjI2T1ByQnpiYzA&usp=sharing
Try this
https://rakeshistom.files.wordpress.com/2015/06/product-to-price-book.png
It’s working for me)
I will try this shortly. How do I get the type field to show in my process? I don’t have that field and it would be a great help if I did.
Type field ?