Working With Process Builder - Part Two

Introduction 

 
Process Builder is a point & click automation tool available on the Salesforce Platform. I have explained the details about the Process Builder Interface in one of my earlier blogs. I will be skipping Process Builder interface-specific details in this blog, so I would recommend you to first go through the blog. This blog is available here: Working with Process Builder - I
 
In this blog, we will look for another process automation solving another real-time business problem using Process Builder. Let's consider the problem statement below to identify the business problem at hand.
 

Problem Statement

 
While adding or modifying the point of contact for any specific account, we need to make sure that contact must have a valid Phone Number & Email ID. If contacts don’t have Phone Number & Email ID, then this information should be copied from Account Details.
 

Analysis of Problem Statement

 
In the real world, as developers, we should always look into the problem statement carefully to identify the best approach to solve it, so adopt this as a rule of thumb.
 
From the problem statement we have:
  • Trigger - New Contact Record added or edited
  • Criteria - If Contact Email Id & Phone Number are empty
  • Action - Update Contact information from Account Details

    • Contact.Email = Account.Email
    • Contact.Phone = Account.Phone
Launch the Org and search for “Process Builder” in Setup Navigation on the left, as shown below.
 
Working With Process Builder 
 
This will launch the “View All Processes” screen where we can see the list of all the processes created earlier.
 
Click on the “New” button.
 
Working With Process Builder 
 
This will launch the New Process Configuration dialog box.
 
Specify the details “Name, API Name, Description, and Process Type” for the new process.
 
Click on “Save” to persist the changes and start the Process designer.
 
Working With Process Builder
 
 Working With Process Builder
 
To add the trigger for the Process, click on “Add Object”.
 
Working With Process Builder 
  1. Click Add Object
  2. Select the trigger target as any desired sObject from Object Dropdown, I choose "Contact" Object-based on the problem statement
  3. Select the trigger condition as when do you like to initiate the process. I choose “when a record is created or edited” based on the problem statement
  4. Click "Save" to save the changes
To add the criteria click on “Add Criteria”.
 
 Working With Process Builder
  1. Click Add Criteria
  2. Enter the name of the criteria to uniquely identifies the criteria by its function
  3. Select applicable conditions to execute actions, I choose “Conditions are met” which means that actions will be executed only when conditions are fully satisfied
  4. Configure condition based on your problem statement:
    1. Contact.Email == Null
    2. Contact.Phone == Null
We set both the values to a global constant collection which is represented by “$GlobalConstant.Null” in declarative development paradigms for Salesforce Development.
 
 Working With Process Builder
  • Evaluate the conditional logic to merge the conditions using logical operators. It follows the format: Condition 1 <logical operator> Condition 2 “Customize my logic” is my preferred option since it gives me maximum flexibility to place conditions more logically in whatever way best suited the requirement.

    Here, I have mentioned “1 And 2”, which mean both conditions 1 & 2 must be evaluated to True to success these criteria

  • Click “Save” to save the changes.
To add the actions click on “Add Actions”.
 
Working With Process Builder 
  1. Click Add Action
  2. As per the business requirement, we need to add a task, so I am selecting “Update Record” as Action Type
  3. Specify the name to uniquely identifies the action, lets’ call it “Update Contact”
  4. Since we are expecting to create a task so we need to select the sObject accordingly. In our case, we will choose “Contact” as Record Type
Working With Process Builder
  1. Select the criteria for updating the records, in our case we need to update the contact record anyways. So we will choose “No criteria – just update the records!”
  2. Based on the problem statement, we need to update the Email & Phone fields of Contact Record
 Working With Process Builder
  • Email
    We have set it to the reference of the “Primary Email” Field of the Account object
Working With Process Builder
  • Phone
    We have set it to the reference to the “Account Phone” Field of the Account object
Working With Process Builder
  • Click “Save” to save the changes
Working With Process Builder
 
To activate the Process click theActivate button in the toolbar as shown below. This action will prompt a confirmation box confirming if you wish to activate this version of the Process.
 
Working With Process Builder 
 
Click Confirm to activate this Process.
 
 Working With Process Builder
 
It is important to note here that Salesforce can maintain multiple versions of the same Process at the same time, but only one version will remain active.
 
Since we have already Activate the latest version of the Process, it now the time to test it.
 
Here is the test plan to validate the working of this process.
 

Positive Test

 
I am demonstrating a positive test in this demo that will satisfy the criteria of the Process and let it updates the fields of Contact Record as expected.
  1. Launch AccountObject list view
  2. Click on “New” button on the toolbar to add a new Account
Working With Process Builder
 
Fill the following details:
  1. Account Name: Specify a suitable account name, I have specified “NewAccount-001”
  2. Primary Email: Specify a suitable email id for the Account
  3. Phone: Specify a suitable phone number for the Account
Working With Process Builder
  • Click Save to add the account.
Working With Process Builder
  • Once account created successfully we need to launch the Contacts Object list view
  • Click on New button in the toolbar to launch a New Contact Screen 
Working With Process Builder
 
Fill in the following details:
  • Salutation, First Name & Last Name: Enter suitable values for each of these fields
  • Account Name: This is the lookup field, use to look up for Account “NewAccount-001” that we have created recently
  • Click “Save” to persist the changes. Here it is important to notice that we haven’t specified Email & Phone Number for the new Contact
Once the contact is created successfully, it triggers the process since the Email & Phone Number is missing for the Contact that we have created just now.
 
Working With Process Builder
Working With Process Builder 
 
The process will update the Contact Details using Account Details and we should be able to see Email & Phone Number copied to the Contact Details on the Contact Screen.
 
Notice carefully and make sure that the phone number and email ID have the same values as we have specified during Account Creation.
 

Summary

 
I would love to leave this for you as an exercise, and if you follow along with this article, it should not be difficult for you anymore.
 
I hope you enjoyed this article. Please leave your comments below to let me know how you liked the content and how you found it helpful.