Best Practices for Optimizing Triggers and Synchronous Code in Q-assign
Salesforce platform being a multitenant architecture, shares it's infrastructure and resources with all users. To avoid overutilization of these resources by any one client, Salesforce enforces Governor Limits. As soon as a transaction exceeds any of the pre-defined limits, it will not be processed and an error will be thrown. To find out more about Salesforce Governor Limits, please visit this page: https://developer.salesforce.com/docs/atlas.en-us.210.0.apexcode.meta/apexcode/apex_gov_limits.htm
To ensure Q-assign is running efficiently, here are some of the best practices for optimizing Triggers and Synchronous Code and avoiding Salesforce Governor Limits:
- Always try to batch/bulky-fy SOQL and DML queries in triggers. Q-assign updates records in a bulkified DML, which means a trigger gets called for each Assignment Group that has at least 1 record to be assigned out through it.
- Each trigger from a single Q-assign job will share the resources (Salesforce governor limits) with other calls of the same triggers. So it is always a good idea to keep SOQL and DML queries to the minimum. One common way to get rid of queries is to replace the parts of code (that run query) with processes (Process Builder), flows and workflows. Any record updates performed within a process, visual flow or workflow are not counted towards query limit.
- Use the “Limit” class in your trigger code to make sure code never actually hits the limit. More details can be found here: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_limits.htm
If a limit is about to hit, then take some alternative path and exit as early as possible. One way could be to mark such records as ‘unprocessed’ and then maybe use another job/batch/process to handle such records. This approach will help identify which records are actually causing limits to be hit and therefore code can be optimized around it.
- Reduce Max Records To Process Per Job setting in QA Control Panel tab so that fewer records are processed in one job and limits are prevented from hitting.
Please contact us at email@example.com for any questions.