function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Daoning ZhouDaoning Zhou 

Process Builder optimization to avoid "Apex CPU time limit exceeded" errors

Hi all,

I am running into the CPU time limit exceeded error when I try to bulk import data into our org. Because I don't have coding knowledge myself, I was hoping to use visual workflows instead. The data that we sync has up to 22 fields that have 0's and 1's for the field input and I want to change these into "Yes" and "No" picklist values. The reason that I didn't want to use a formula field is because sometimes we also manually create records and I wanted to be able to choose Yes/No values. I also couldn't use checkboxes as per the instructions I received. 

Here is process flow I created

User-added image

What I did is I created 22 action groups for each of the binary fields. The action group criteria was to check if the picklist value is a 0 or 1 and if so, it'll kick in the immediate actions.

Here is part of the error message I received below. It seems like it's running but it's just slow..? 
Flow Details
Flow Name: Listing_Workflow_for_Binary_Fields
Type: Workflow
Version: 3
Status: Active

Flow Interview Details
Interview Label: Listing_Workflow_for_Binary_Fields-3_pba__Listing__c
Current User: Keith Kiefer (005150000066qU6)
Start time: 1/22/2017 4:13 PM
Duration: 17 seconds

How the Interview Started
Keith Kiefer (005150000066qU6) started the flow interview.
Some of this flow's variables were set when the interview started.
myVariable_old = null
myVariable_current = a091500001MLez0AAD
RecursiveCountVariable = 0.00

ASSIGNMENT: myVariable_waitStartTimeAssignment
{!myVariable_waitStartTimeVariable} Equals {!Flow.CurrentDateTime}
Result
{!myVariable_waitStartTimeVariable} = "1/22/2017 4:13 PM"

DECISION: myDecision
Executed this outcome: myRule_1
Outcome conditions: and
1. {!formula_myRule_1} (true) Equals true
Logic: All conditions must be true (AND)

DECISION: myRule_1_pmetdec
Executed this outcome: myRule_1_pmetnullrule
Outcome conditions: or
1. {!myVariable_old} (null) Is null true
Logic: One condition must be true (OR)

RECORD UPDATE: myRule_1_A1
Find all pba__Listing__c records where:
AssessmentsYN__c Equals 1
Id Equals {!myVariable_current.Id} (a091500001MLez0AAD)
Update the records’ field values.
AssessmentsYN__c = Yes
Result
All records that meet the filter criteria are ready to be updated when the next Screen or Wait element is executed or when the interview finishes.

RECORD UPDATE: myRule_1_A2
Find all pba__Listing__c records where:
AssessmentsYN__c Equals 0
Id Equals {!myVariable_current.Id} (a091500001MLez0AAD)
Update the records’ field values.
AssessmentsYN__c = No
Result
All records that meet the filter criteria are ready to be updated when the next Screen or Wait element is executed or when the interview finishes.

DECISION: myDecision2
Executed this outcome: myRule_3
Outcome conditions: and
1. {!formula_myRule_3} (true) Equals true
Logic: All conditions must be true (AND)

DECISION: myRule_3_pmetdec
Executed this outcome: myRule_3_pmetnullrule
Outcome conditions: or
1. {!myVariable_old} (null) Is null true
Logic: One condition must be true (OR)

RECORD UPDATE: myRule_3_A1
Find all pba__Listing__c records where:
AuctionYN__c Equals 1
Id Equals {!myVariable_current.Id} (a091500001MLez0AAD)
Update the records’ field values.
AuctionYN__c = Yes
Result
All records that meet the filter criteria are ready to be updated when the next Screen or Wait element is executed or when the interview finishes.

RECORD UPDATE: myRule_3_A2
Find all pba__Listing__c records where:
AuctionYN__c Equals 0
Id Equals {!myVariable_current.Id} (a091500001MLez0AAD)
Update the records’ field values.
AuctionYN__c = No
Result
All records that meet the filter criteria are ready to be updated when the next Screen or Wait element is executed or when the interview finishes.

I had a few questions regarding how the process builder operates I was hoping one of you could help me understand

1) Is there a difference between the criteria for the action group and the criteria for the immediate action? Since the flow evaluates all the actions regardless, I'm not sure if this makes much of a difference. 
2) Does flow recursion significantly increase the CPU time?
3) I was also thinking of making parallel PB flows to make the workflow look more organized on the back end. Is that okay or would it just cause more problems for me in the long run?

Thanks for reading. I might be missing a few pieces due to a lack of coding knowledge so any insight would be greatly appreciated!
AdikAdik
I do agree with CPU time out issues on Process Builder. Don't create multiple PBs. my suggestion is put all 22 Fields Updates in single Rule and single Update.
Dn't Check for Value is 1 or 0, instead Update the Target Field with Formuala.
Target Field One = CASE(Target Field One, 1, Y, 0, N,Target Field One)
This wayKeep the Value as is If already Converted, if not convert to new Value.
Sam LimSam Lim
Just curious if you were able to solve your problem?  I'm experience CPU limits with my process builders as well.

Thanks!
ksadler1982ksadler1982
Hello - have either of you resolved these issues?  We are in a critical state with hitting cpu time outs from process builders.  It is to the point where it is happening on a single record insert via api.  We have triggers and workflows running on the object as well, but these are optimized and the record saves fine if there are 0 process builders running on this object.   The pb can be as basic as a singl node field update.
Veena Sundara-HeraguVeena Sundara-Heragu
Have you got resolution for this?
Steven Wilson 47Steven Wilson 47
Hi anyone got any update for this, we seem to be hitting Apex CPU time limits,

We have identified the below to investigate:
 
  • Apex 
  • Optimize our Loops
  • Use Triggers patterns
  • Using future methods
  • Nested loops
  • Using SOQL aggregation
  • Process builder visual workflows 
  • Flows that runs from Process builders and also scheduled flows
  • General Salesforce Workflows with field updates etc
  • Validation rules, particularly ones with long formulas that utilise CPU time
  • rollup summary fields which are a product feature


 
RayAllenRayAllen
Does using flows rather than updating via process builder fix this issue for others?
guestadmin Tomguestadmin Tom
Hi everyone,

Try to find the process builder logic where you see the possibility to move it to the apex invokable method and then adding a future method to it. I think you seem a bit confused but let me clear up your ambiguity.
We know that Salesforce imposes a limit on the CPU usage that can be consumed in a given transaction, which is approximately 10 seconds for Synchronous, and 60 seconds for Asynchronous. For more details, you can refer here (https://salesforcebitsandbytes.com/how-to-solve-the-apex-cpu-time-limit-exceeded-due-to-process-builder/)