You need to sign in to do that
Don't have an account?
Marco Santos
Avoid SOQL Queries Inside FOR Loops
Hi,
Could enybody tell me how to change this for loop to put the SOQL outside the for loop to efficiently query records?
I will be apreciate for help
Thanks
Could enybody tell me how to change this for loop to put the SOQL outside the for loop to efficiently query records?
for (Opportunity Opp :Trigger.new){ Boolean flag = false; Account a = [Select id, name from Account where Id = :Opp.AccountId][0]; if (a.Name == 'XB Sample') { flag = true; } }
I will be apreciate for help
Thanks
To avoid having a query inside the for loop, the structure you need to follow will be :
1) Loop through all the records and collect your condition criteria
2) Query
3) Loop Through the results to perform in your operation.
Coming to your problem, the result will look something like:
Hope it helps.,
Thanks,
Balaji
All Answers
To avoid having a query inside the for loop, the structure you need to follow will be :
1) Loop through all the records and collect your condition criteria
2) Query
3) Loop Through the results to perform in your operation.
Coming to your problem, the result will look something like:
Hope it helps.,
Thanks,
Balaji
Thank you