Process Builder is a way of automating business processes. It is an upgraded version of the Workflow Rule. Whenever a user creates a process, the system automatically creates a Visual Workflow – and a Flow Trigger (which is now deprecated) – to call the Flow. Creation of the Flow happens behind the scenes; and therefore, a user does not need to interact with these ‘shadow’ (behind the scenes) Flows. Process Builder is a powerful tool for system administrators and developers to implement business processes without writing code. However, with great power comes great responsibility – If a user starts creating a new process for each requirement – or creating processes without understanding Salesforce limitations – then, a user may encounter many issues, either in future or, while testing/deployment phase. Let us start with one of the most common error – Mixed Data Manipulation Language (DML) Operation Error.
What is Mixed DML Operation Error?
When DML operations on certain sObjects sometimes referred to as setup objects (such as a User Object), along with, on the non-setup object (such as Accounts), in the same transaction, then, a Mixed DML error is thrown at a User.
The Mixed DML error is generated – when a User performs DML actions on Setup and non-Setup Objects in the same transaction -because some sObjects affect the user’s access to records in the org. Therefore, a user must insert or update these types of sObjects in different transactions to prevent operations from happening with incorrect access-level permissions. For example, a user cannot update an account, and a user role, in a single transaction. However, deleting a DML operation has no restrictions (reference Salesforce help).
Below, I will show you how to use Process Builder to avoid getting a Mixed DML Operation Error.
First, I will perform DML operation on Setup (User) and non-Setup (a Custom Object called Leave Balance) Objects in the same transaction. This will generate a Mixed DML Operation error because one cannot perform a DML operation on Setup and non-Setup objects in the same transaction.
Next, I will show you how to use Time-dependent/Scheduled Action, in the Process Builder, to perform DML operations on Setup and non-Setup Objects in the same Process without incurring a Mixed DML operation error. The time-dependent/scheduled action is used because it helps in separating DML operations on Setup and non-Setup objects.
Business Use case
Donna Serdula is working as a System administrator at Universal Containers. They just implemented Leave Management System in Salesforce. Serdula has a requirement from her manager that, as soon as a new user is created in Salesforce do the following:
- Auto update Allow Forecasting checkbox on the user record.
- Auto Credit one leave for each category – Medical, Casual and Earned.