Getting Started with Process Builder – Part 77 (Auto add products to new Opportunity)

Once Sales Reps create a new Opportunity, the next step is to add Price book and products to it. Products are physical goods or services that you sell to customers. Your Sales reps can use products to generate sales quotes, contracts or orders. Price Book is a catalog in which regular selling price of products is listed. Price books are used for selling products at different prices based on geography, volume, government contracts, not-for-profit clients, strategic clients etc.

In Salesforce, one product can be associated with multiple Price Books, and one Price Book can have multiple products. Yes! You are right! This calls for a Junction object. And, lo and behold, we have one known as Price Book Entry! Price Book Entry is a junction object between Product and Price Book, as shown in the following screenshot:

Business Use case

Martin Jones is working as a System Administrator at Gurukul on Cloud (GoC). He has created a process using Process Builder to automatically assign Pricebook to new opportunity based on record types, as mentioned below:

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

It’s working good, and Sales reps are happy. However, Martin received another requirement from VP of Sales– when Manufacturing Price Book is added to a newly created opportunity, automatically add the following products to it:

iPhone 7 – Quantity (3) – Sales Price ($0)

iPhone 7 Plus – Quantity (3) – Sales Price ($0)

Solution for the above business requirement

The requirement is interesting. So, we will not only create a solution for the existing requirement – using Process Builder – but, we will also plan ahead! In my next blog, I will show you how Martin can avoid re-modifying the process again and again as and when the requirements change.

Create custom labels to store Price book entry Id of default products

First, run the following query (Select id, Name from pricebookentry where name IN (‘iPhone 7′,’iPhone 7 Plus’) and Pricebook2Id=’01sB00000006aeb’) in developer console to get thePriceBookEntryID for iPhone 7 and iPhone 7Plus, as shown in the following screenshot:

Click on Setup (Gear Icon) | Setup | User Interface | Custom Labels

Click on New Custom Labels; it will open a new window for you. Now, create new custom labels to store the product (iPhone7 and iPhone 7 Plus) Ids, as shown in the following screenshot:

Repeat the above process if you want to add more default products to newly created opportunity.

The next step is to create process builder to solve the requirement. Instead of creating a new process for this requirement we will clone the existing process builder.

Cloning existing Process

Let us clone the process we created inpart 14.Click on the Clone button available on the button bar. It will open a popup for you. Under Save Clone As, select Version of current process option. It will look like the following screenshot:

Once you are done, click on the Save button.

Now you can modify the process as per the business requirement. In our case, we will add two immediate actions to add two default products (iPhone7 and iPhone 7 Plus).

The next step is to addanImmediate action under Manufacturing criteria node to add product iPhone 7. For this select Action, Type Create a Record, Use Field Picker to map the fields, as shown in the following screenshot:If you do not know how to use Custom Label in process builder then, consider reading this article Just Say no to hard-coded ID.

Repeat the above step, and add one moreImmediate action under Manufacturing criteria node to add ProductiPhone 7 Plus. It will look like the following screenshot:

Once done, click on the Save button. This will redirect you to Process canvas. Finally, theProcess will look like the following screenshot

Don’t forget to active the Process by clicking on the Activatebutton.

It’s time to test the Process

From now onwards, if a business user creates an Opportunity with record type Manufacturing, then, the Process Builder will automatically add price book and products to it.

Navigate to the Opportunitytab, and create a new opportunity for Manufacturing record type.

Once done, click on the Savebutton. The process will automatically add Price book and default Products to it, as shown in the following screenshot:

Rakesh Gupta

Ketan

This work Perfect when we execute the apex code manually. But If I want Automatic to extract the PriceBookEntryID for Product and assign it to the Opportunity. Because I have name of Product and PriceBook. And using that I want to add that product to Opportunity