You need to sign in to do that
Don't have an account?

Convert Process Builder to trigger
I had created a Process Builder which was working fine in the lower sandboxes. In production however, it is causing errors and giving the following message: The flow tried to update these records: null. This error occurred: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: pi.LogAccountChange: System.LimitException: Apex CPU time limit exceeded. You can look up ExceptionCode values in the SOAP API Developer Guide [developer.salesforce.com] Flow Details Flow API Name: Opportunity_Recalculate_Rating Type: Record Change Process Version: 4 Status: Active Org: Lifetouch (00D15000000kLl0) Flow Interview Details Interview Label: Opportunity_Recalculate_Rating-5_InterviewLabel Current User: Integration User (005150000073iiO) Start time: 3/22/2019 1:57 AM Duration: 15 seconds How the Interview Started Integration User (005150000073iiO) started the flow interview. Some of this flow's variables were set when the interview started. myVariable_old = Opportunity (0061500000WK2cKAAT) myVariable_current = Opportunity (0061500000WK2cKAAT) ASSIGNMENT: myVariable_waitStartTimeAssignment {!myVariable_waitStartTimeVariable} Equals {!$Flow.CurrentDateTime} Result {!myVariable_waitStartTimeVariable} = "3/22/2019 1:57 AM" DECISION: myDecision Executed this outcome: myRule_1 Outcome conditions: {!formula_myRule_1} (true) Equals true RECORD UPDATE: myRule_1_A1 Find all Opportunity records where: Id Equals {!myVariable_current.Id} (0061500000WK2cKAAT) Update the records’ field values. LPP_Rating__c = {!formula_4_myRule_1_A1_9963437625} (B) 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 Account records where: Id Equals {!myVariable_current.AccountId} (0011500001LkYu4AAF) Update the records’ field values. Fall_Rating__c = {!formula_3_myRule_1_A2_9151511649} (B) 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_A3 Find all Account records where: Id Equals {!myVariable_current.AccountId} (0011500001LkYu4AAF) Update the records’ field values. Spring_Rating__c = {!formula_2_myRule_1_A3_6475583567} (A) Result Failed to update records that meet the filter criteria.
And this error is just a snippet. It actually gives a page long message with the same thing. After doing research, I found out that PB take twice as long to execute as opposed to Apex triggers. So my goal is to convert this Process Builder to an Apex trigger. Unfortunately, I am not a developer and would love to get some guidance/starting step into converting this PB into Apex trigger. The Process Builder is below:
the build formula is: AND ( NOT(ISBLANK([Opportunity].LPP_Rating__c )), TEXT([Opportunity].Collection_Status__c) <> "Open", [Opportunity].Retake__c = false, OR ( ISCHANGED([Opportunity].Total_Payments__c), ISCHANGED([Opportunity].Sales_Tax_Rate__c), ISCHANGED([Opportunity].Reorder_Payments__c), ISCHANGED([Opportunity].Total_Production_Value__c), ISCHANGED([Opportunity].Discount__c), ISCHANGED([Opportunity].Children_Photographed__c), ISCHANGED([Opportunity].Commissions_Paid__c) ) )
The imediate action is:
and the value section has this written:
Basically, what this process is doing is that there is a Rating field that gets updated based on the Contribution Margin formula. However, if any component value in the contribution formula changes, then it updates the rating field. I am guessing this will be a before update trigger. Any help would be greatly appreciated. Thank you
And this error is just a snippet. It actually gives a page long message with the same thing. After doing research, I found out that PB take twice as long to execute as opposed to Apex triggers. So my goal is to convert this Process Builder to an Apex trigger. Unfortunately, I am not a developer and would love to get some guidance/starting step into converting this PB into Apex trigger. The Process Builder is below:
The imediate action is:
All Answers
1. Can you copy the formula from immediate action here.
2. Do you already have any Apex trigger on Opportunity?
Thanks.
No there are no opportunity triggers yet. This will be the first one. Our org is brand new. The formula is below:
if((TEXT([Opportunity].Program_Type__c) = 'Same Day Proof' || TEXT([Opportunity].Program_Type__c) = 'Family Approval') && [Opportunity].Contribution_Margin__c >= 0.62, 'A',
if((TEXT([Opportunity].Program_Type__c) = 'Same Day Proof' || TEXT([Opportunity].Program_Type__c) = 'Family Approval') && [Opportunity].Contribution_Margin__c >= 0.45 && [Opportunity].Contribution_Margin__c < 0.62, 'B',
if(TEXT([Opportunity].Program_Type__c) = 'Same Day Proof' && [Opportunity].Contribution_Margin__c >= 0.11 && [Opportunity].Contribution_Margin__c < 0.45, 'C',
if(TEXT([Opportunity].Program_Type__c) = 'Same Day Proof' && [Opportunity].Contribution_Margin__c <= 0.1, 'D',
if(TEXT([Opportunity].Program_Type__c) = 'Family Approval' && [Opportunity].Contribution_Margin__c >= 0.01 && [Opportunity].Contribution_Margin__c < 0.45 && [Opportunity].Percent_of_Sale__c >= 0.3, 'C',
if(TEXT([Opportunity].Program_Type__c) = 'Family Approval' && [Opportunity].Contribution_Margin__c <= 0.0 || [Opportunity].Percent_of_Sale__c < 0.3, 'D', null))))))