Salesforce Process Builder: How to Troubleshoot Salesforce Process Builder Flows & Other Development Artifacts
In this article, we will look into the
detailed configuration steps to enable Salesforce development environment to
support debugging of development artifacts like Workflows, Database Queries,
REST API Calls, Apex Code and much more.
We have a couple of approaches to
debug development artifacts in Salesforce. In the following sections we will
see how we can modify the process to make it raise an exception and then we
will explore the configuration steps involved with each of the approaches.
Generate Exception for Demo
To demonstrate the debugging process
we need to first generate an error and then we will analyze it step by step.
I would recommend you to go through
the following articles I wrote earlier explaining details on how to develop
automation workflows using Process Builder.
I am repeating the same steps here
quickly to show you a test scenario which will end up with an error in the
following steps:
Step-1:
Launch Process Builder, click on “New”
Button
Step-2:
Add a trigger for "Contact"
SObject
Step-3:
Specify trigger name "Contact"
Step-4:
Select trigger condition "when a
record is created or edited"
Step-5:
Add criteria
Step-6:
Specify criteria name "Empty Email
& Phone"
Step-7:
Select criteria condition "Conditions
are met"
Step-8:
Set condition as (If Contact Email & Phone are empty)
Step-9:
Add Action
Step-10:
Specify action name "Update
Contact"
Step-11:
Select record as "Contact"
SObject
Step-12:
Select the action condition as "No
criteria-just update the records!"
Step-13:
Set contacts field with field reference of Account associated with Contact
details.
Field assignment as follows: (Contact
-> Email = Account -> Email), (Contact -> Phone = Account -> Phone)
Step-14:
Launch "Contact" list view
Step-15:
Click "New" to add a new
contact record
Step-16:
Once added it will look like this
To generate the error, I have removed
some of the important fields like Phone Number, Email and most importantly I
have removed the value from Account Field which a lookup field and if you
remember the process we defined above will try to copy Email and Phone
information from the associated account to contact record
Now if I try to save the record it
will trigger the process that we defined earlier and try to set the values as
defined in the Add Action Step
It will fail since we have removed the
Account information from the Contact record. As a result of which process try
to query the Email & Phone information from a null referenced field
(Account)
We will see an error similar to the
one shown below:
Now in the following sections we will look
for the different approaches to debug Salesforce Artifacts. Since this article
is focused on debugging Salesforce Process Builder, we will configure the
following approaches to debug Process Builder flows only.
Approach -1: Using Apex Email
- Configure "Process Automation
Settings"
We need to make
few changes to these settings as shown in the steps below:
Step-1:
Search for "Process Automation
Settings" as shown below
Step-2:
Click "Process Automation
Settings"
Step-3:
Select "Apex Exception Email
Recipients" from the dropdown as shown
- Configure "Apex Exception Email"
We need to first add a required user to the
recipient list so that the user gets the error details in the email
Step-1:
Search for "Apex Exception
Email" as shown below
Step-2:
Click "Apex Exception Email"
Step-3:
Click "Add Salesforce User"
to add the user to the recipient list
Step-4:
This will launch the "Add
Salesforce User" screen, click on the search name icon to find the
Salesforce User Directory
Step-5:
This will launch the User Lookup screen, type the name of the user you are
trying to add
Step-6:
Click "Go"
Step-7:
If the search can find a match as per your search keyword, then it will be
shown to the "Search Result"
section. Click on the user name you like to add as a recipient
Step-8:
This will close the lookup window and copy the selected user in the name
textbox
Step-9:
Click "Save" add the
selected user to the recipient list
Step-10:
After the user is added to the recipient list, it will look like as shown
To utilize this approach first we have
to generate the exception and then we will perform a detailed analysis of the
error information received in the email
To generate the exception please refer
to the "Generate Exception for
Demo" section down below. Here I am copying the screenshot of the
error generated from this section:
Analysis:
Now we will analyze the error information that we received as part of debugging
through Apex Email
We can see the email received as shown
below:
Step-1:
We can see the subject line giving some idea on the source of exception, as we
can see it the flow by the name "Update_Contact_Details"
throws this exception
Step-2:
We can see the email id that Salesforce used to send this error email to the
recipient
Step-3:
We can see that error occurred since "Account.Primary_Email__c"
returns a null value, which is expected as we have removed the account
information associated with the current contact record
Step-4:
If we analyze the email body we can see some obvious information like "Flow API Name:
Update_Contact_Details". With this information, we can conclude that
this error occurred in flow with the name as specified in Flow API Name
Step-5:
We can see under which user credential this flow executed, like in this case
this flow was executed by user "Prashant
Bansal"
Step-6:
This is the most important piece of information where Salesforce is informing
that both Email & Phone fields could not be resolved for obvious reasons
Approach -2: Using Developer Console Logger
Developer Console Loggers is a very
powerful mechanism to debug almost every kind of functionality on the
Salesforce Platform. We will analyze the exceptions occurred as shown in the
followings steps:
- Configure Log Level
To track exceptions from different sources
(Apex, Database, Workflows and so on) we need to configure the log level within
Developer Console > Debug Menu as
shown below:
Step-1:
Click "Developer Console"
to launch developer console
Step-2:
Click on the "Debug" menu
Step-3:
Click on "Change Log Levels"
Step-4:
On "Change Log Level"
screen, click on "Add/Change"
under "General Trace Settings for
You"
Step-5:
On the "Change Debug Level"
screen, click on "Add" to
add a new debug level with custom configuration
Step-6:
Enter the name of new Debug Level, lets' call it "Process_Builder"
Step-7:
This is important to understand that we can add the level and configure each of
the sources and define what level of tracing we need.
We can reach out to the details of "Debug Log Categories" and “Debug Log Levels" by following
Salesforce documentation at Debug Log Levels
Step-8:
In our case, we need to trace exception coming from Workflows, so in this
custom Debug Level we will turn off tracing for all log categories except "Workflow". We can turn off
tracing by selecting "None"
from the dropdown on the custom debug level row. We will select "FINER" as log level which
gives the best available data for exception generated on any of the Workflows
across Salesforce Org
That is all we need for the
configuration.
To generate the exception please refer
to the "Generate Exception for Demo"
section down below. Here I am copying the screenshot of the error generated
from this section:
Analysis:
Now we will analyze the error information that we received as part of the debug
log of the developer console.
Once exception occurred we can see a
new log entry on the Developer Console.
Double click it to open the log
In
this log we can focus on some important entries as mentioned below:
"WF_CRITERIA_BEGIN": This log entry gives details on the name of
the sourcing process (Update_Contact_Details) that causes this exception
"FLOW_VALUE_ASSIGNMENT": This log entry gives details on data
assignment to the flow variables, this could be useful to see what values were
passed to these variables during workflow runtime
"FLOW_ELEMENT_ERROR": This log entry gives the details on specific
error information and can be very helpful to point us out quickly to identify
the true cause of the exception
"WF_FLOW_ACTION_ERROR_DETAIL": This log entry gives the details on exception
statement, it is the same statement that you have seen as exception message on
the User Interface
We can double click on any of the log
entries to open it as a message box as shown
With this information, it will be easy
to track down the exceptions occurred in Salesforce automation flows &
other development paradigms (Process Builder, Workflows, Visual Flows, Apex,
Database, REST APIs and much more).
Hope you enjoyed this article. Please leave your comments to let me know how you do like the content and how you do find it helpful to learn the topic.
Comments
Post a Comment