Salesforce offers multiple tools to automate your company’s business processes. Oftentimes we run into confusion deciding whether to choose Process Builder or Apex triggers when both are capable of doing some of the same functions. Let’s take a closer look at some of the pros and cons of using Process Builder compared to Apex trigger.
Process Builder – Pros:
The IT Leader's Guide to Multicloud Readiness
This guide provides practical key insights and important factors to consider to make informed decisions in your multicloud journey.
We recommend starting with Process Builder, especially for processes that can be simplified to if/then statements. Below are some ideal scenarios for using it:
- Process Builder can do the following actions without Apex code:
- Create records and set field values
- Update related records
- Create Chatter posts
- Send an email
- Create an approval
- Simple triggers like populating a lookup field based on certain criteria can now be automated in Process Builder
- Launch an automated flow.
- Call an Apex class.
Process Builder – Cons:
Below are some limitations to using Process Builder and the advantages of using Apex triggers to address these particular scenarios:
- Process Builders cannot handle before DML It executes after a record has been created or updated. Whereas Apex triggers can handle both before and after DML operations.
- Process Builder cannot handle delete and undelete DML. Whereas Apex triggers can handle all DML operations.
- An error reported in Process Builder is more generic which makes it difficult to find the origin of the error. With Apex triggers, exception handling can be made more specific.
- It is all or none in case of Process Builder failure. But with Apex triggers partial success is possible.
- Whenever a particular use case is not possible using Process Builder, consider using Apex triggers. For example, consider the below use case:-
A custom field on a Parent object which is based on the field related to the max (roll up) among the child records. Since roll-up functionality involves insert, update, delete and undelete operations, using an Apex trigger is the best option in this scenario.