You need to sign in to do that
Don't have an account?
LIM AI KHOON
Query outside the for loop in triggers?
Hi, I get this error:
System.LimitException: Too many SOQL queries: 101
May I know how to improve this code? Maybe to put query outside the trigger.new loop
System.LimitException: Too many SOQL queries: 101
May I know how to improve this code? Maybe to put query outside the trigger.new loop
trigger pullCommentsApproval on Pricing__c (before update) { Map<Id, Pricing__c > oppMap = new Map<Id, Pricing__c >([ Select (Select Comments From ProcessSteps where StepStatus IN ('Approved','Rejected') ORDER BY CreatedDate DESC) From Pricing__c WHERE Id IN : Trigger.new]); for(Pricing__c opp: Trigger.new) { Pricing__c opp1 = oppMap.get(opp.Id); opp.Approver_Comments__c = ''; for (ProcessInstanceHistory processStep : opp1.ProcessSteps) { opp.Approved_Date__c = DateTime.parse(system.now().format()); } opp.Approver_Comments3__c = 'aa'; } }
Try Below TRigger Please Mark It As Best Answer If It Helps
Thank You!
I tried the given code but hit errors.
Line 9: Invalid type: ProcessSteps
Line 11: Variable does not exist: Approved_Date__c
Line 15: DML operation Update not allowed on List<ProcessInstanceHistory>
I am not getting what excatlly you want to do, and what is meant of below linw
for (ProcessInstanceHistory processStep : opp1.ProcessSteps) {
Please clear this line then after that i will share a perfect solution
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Actually, I want to put the approval comment for the pricing in a field so that we can display it inside the report. But When I perform one flow, it give me an error System.LimitException: Too many SOQL queries: 101
Yes ,
becasue you are decleare variable ProcessSteps of Object type (ProcessInstanceHistory) and using for Object(ProcessSteps)
Please clear it