Last Updated on December 15, 2020 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 Process Builder.
Objectives:
This blog post will help us to understand the following
- Using process builder to auto-assign Price book when an opportunity is created, based on the opportunity record type.
- The opportunity object and creating 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 process builder
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):
While this can be solved using various automation tools like Apex or Flow, we will use Process Builder. This is not something that can be accomplished with Workflow Rules.
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
- Using the Developer Console retrieves the PricebookId fields for the two Price books – Manufacturing and Retail.
- Create a process builder 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 to go through the following Flow diagram and understand it.
Let’s begin building this automation process.
Guided Practice (We-do):
There are 8 steps to solve Martin’s business requirement using Process Builder. We must:
- Create two record types – Manufacturing and Retail
- Create two price books – Manufacturing and Retail
- Find the price books Ids for Manufacturing and Retail
- Creating a custom label to store price book Ids
- Define process properties
- Define evaluation criteria
- Define process criteria
- Add action – update records
Step 1: Create Two Record Types
- Click Setup.
- In the Object Manager, type Opportunity.
- Clicks 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: Find the price books Ids for Manufacturing and Retail
The next step is to find out the Id of price books Manufacturing and Retail. One possible workaround is to use the Developer Console.
- Click Setup | Developer Console
- In the Query Editor, run the following SOQL query
- Select id, name from pricebook2 where (name=’manufacturing’ or name=’retail’)
- Make sure to copy the Ids.
Step 4: Creating a Custom Label
- Click Setup.
- In the User Interface, type Custom Labels.
- Click on the New Custom Label button.
- Enter Short Description the Name will auto-populate.
- Now enter the Manufacturing Price Book Id in the Value.
- Click Save.
- Repeat steps 1-6 to create another label to store the Retail Price Book.
Step 5: Define Process Properties
- Click Setup.
- In the Quick Find box, type Process Builder.
- Select Process Builder, then click New.
- Name the Process and click the Tab button. The API Name will populate.
- As a best practice, always input a description.
- The process starts when A record changes.
- Click Save.
Step 6: Define Evaluation Criteria
- Click on the Add Object node to begin selecting the evaluation criteria.
- Select the Opportunity object from the dropdown list.
- Start the process only when a record is created.
- Click Save.
Step 7: Define Process Criteria
- Click the Add Criteria node to begin defining the process criteria.
- Name the criteria.
- The criteria should execute actions when the conditions are met.
- Set Conditions
- Row 1
- Field: Opportunity | RecordTypeId
- Operator: Is null
- Type: Boolean
- Value: False
- Row 1
- Select All of the conditions are met (AND).
- Click Save.
Step 8: Add Action – Update Records
- Below Immediate Actions, click Add Action.
- For Action Type, select Update Records.
- Name the action.
- Select the option Select the Opportunity that started your process record type.
- The criteria for updating records should be No criteria – just update the records!
- Set new field values for the records you update:
- Row 1:
- Field: Price Book ID
- Type: Formula
- Value: IF([Opportunity].RecordType.Name=’Manufacturing’,$Label.Manufacturing_Price_Book_Id ,IF([Opportunity].RecordType.Name=’Retail’,$Label.Retail_Price_Book_Id ,[Opportunity].Pricebook2Id) )
- Row 1:
- Click Save.
Almost there! Once everything looks good, click the Activate button.
Note:- Before you activate your process, you will want to make sure that you have assigned data in the correct format because Process Builder obeys validation rules. If some fields are required by using validation rules, then make sure you have added those fields. Conversely, if some fields are required on the page layout, you can ignore those fields.
Proof of Concept
Now onwards if a business user creates an Opportunity with any of these two record types, then Process Builder 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:
Hope you all enjoyed learning about assigning Pricebook depending on the selected record type of an opportunity using Process Builder. I shared here one way of solving this use case using Process builder. Feel free to solve this use case with a different approach and share it here so I and my readers can enjoy learning about them. If you have any ideas, insights, or questions you are most welcome to share them with me.
Let me know by Tweeting me at @automationchamp, or find me on LinkedIn.
Author: - Rakesh Gupta Technical Editor: - Mrudula Jarugula
23 thoughts on “Getting Started with Process Builder – Part 14 (Automatically assign Pricebook based on Opportunity Record Type)”
Pingback: Getting Started with Lightning Flow – Part 1 (Understand, Create & Use Variables in Flow!)
Brijesh Kumar
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)
Rakesh Gupta
Please send me complete error message or Developer Console Log
Pingback: Getting Started with Process Builder – Part 77 (Auto add products to new Opportunity)
Pingback: Getting Started with Process Builder – Part 15 (An introduction to version control)
Pratima Rana
Great! Thanks a ton 🙂
Rakesh Gupta
Good luck with implementation, and let me know how it goes.
Pratima Rana
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
Rakesh Gupta
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.
Elizabeth Haynie
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?
Rakesh Gupta
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.
Rakesh Gupta
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
Elizabeth Haynie
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!
Rakesh Gupta
🙂
Chris
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.
Rakesh Gupta
You can ignore the type field
Chris
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
Rakesh Gupta
Can you please post me the snapshot of the debug log and Process Builder.
Chris
Screen Shots of each are at the link.
https://drive.google.com/folderview?id=0B-eUYDYy6F8yWjI2T1ByQnpiYzA&usp=sharing
Rakesh Gupta
Try this
https://rakeshistom.files.wordpress.com/2015/06/product-to-price-book.png
It’s working for me)
Chris
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.
Rakesh Gupta
Type field ?
Pingback: Getting Started with Process Builder – Part 15 (An introduction to version control) « Rakesh Gupta's Blog