Is it better to have long process or multiple processes? Apex CPU Limit Issue - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Dan BennettDan Bennett 

Is it better to have long process or multiple processes? Apex CPU Limit Issue

I have come across an issue where I am exceeding Apex CPU time limit and I am wondering if I should just break my long process down into different processes but am unsure whether this will even help. 

Basically, I have an object that when the status changes it does xyz but it is a bit long so I wondering if I should break it apart into one process for each status. The image below hopefully will give you an understanding of what I mean.

User-added image

If you want to a look at what each process does, here is a link to a screen recording. :)
The video will show a little different at the bottom portion because I added a scheduled process to update another object to start another process that updates records because from my knowledge if a process triggers another process it adds to the Apex CPU limit. But my knowledge is minimal so if someone has insight here that would be great! 

If you read all of this I greatly appreciate you and any help you can provide. 

Mary TaglerMary Tagler
Generally the best practice rule of thumb is one prices per object. We don't do that it in my org (it was like that when I started), but we do group related functionality into a single process with multiple nodes.
Dan BennettDan Bennett
Totally makes sense. The fewer processes per object the fewer users complaining about watching the spinning save icon. 

However, in terms of Apex CPU Limits being affected; does the length of the process affect the 10,000 milliseconds CPU Limit?

I have also resolved the issue that prompted this post but what I found interesting is that the fix was to schedule out an action that updates another object that then triggered a new process to occur and update a related record. When I did this my CPU Limit Issue was resolved.

If someone wants to explain that would be awesome! I am very new so any insights are helpful :)
John KnightJohn Knight
Hi Daniel, the Salesforce recommended best practice is one per object like Mary referenced.  In my personal opinion, it can also make sense to create one per record type if the record types are substantially different in terms of their business process and the automation that goes with them.

One key to optimizing performance is to set the criteria to run the actions only when you need them to.  For example, do you need the process to run every time the record is edited or only when certain fields are changed?

In your case, you are using an interesting workaround for the limitation that you cannot batch Process Builder the same way you can with Apex.  I haven't seen that be an issue except when doing data loads with a large batch size though.  

Dan BennettDan Bennett
Hi John, thanks for your reply. You are right on the money. I have an integration that updates hundreds of records at a time. When I tested my process out as a single user the process worked, but when you batch update multiple records it fails because of the CPU limits. The reason I was getting CPU limits was 2 big processes on different objects firing at the same time when a batch update occurs.

John KnightJohn Knight
Hi Daniel, when I do uploads that cause this error with data loader, and easy solution is to decrease the batch size.  In the worst cases, I have decreased it all the way to one record at a time.  I'm curious if there is any ability to control the batch size for your sync in a similar way.
Dan BennettDan Bennett
John, you are right on the money again. We decreased the size to ten and it fixed the issue but I may start to see more API calls. I should be fine but I have multiple integrations and API call limit could be an issue. Only at 40%-50% usage in a 24hr period so not worried right now but still something I need to consider if I am updating records with third-party integrations. *Daniel Bennett* Marketing & Systems Manager *The Kite Team* - Keller Williams Infinity Direct: 224-588-3266 Office: 847-877-9881 Learn More About Daniel *Recommended By:* Shark Tank - Barbara Corcoran US99.5 - Roman & Stylz WSCR - Laurence Holmes KISS FM - Fred & Angi WBBM - Jeff Joniak WGN - Steve Cochran & John Williams