You need to sign in to do that
Don't have an account?
EdCode
What are the "benefit of SOQL for loop record batching in triggers"
Hello,
Here is a phrase (highlighed in red below) I do not understand in this Trailhead: Buld Apex Triggers.
I totally do understand the benefits of bulkifying SOQLs and DMLs in apex triggers and/or apex Classes.
But, I think this phrase (forgive my poor English) is refeering to statements where you combine a for each loop and an SOQL ? Like below, in lines 5 and 6:
What do you mean by "benefit of SOQL for loop"?
Thank you very much.
Here is a phrase (highlighed in red below) I do not understand in this Trailhead: Buld Apex Triggers.
I totally do understand the benefits of bulkifying SOQLs and DMLs in apex triggers and/or apex Classes.
But, I think this phrase (forgive my poor English) is refeering to statements where you combine a for each loop and an SOQL ? Like below, in lines 5 and 6:
trigger SoqlTriggerBulk on Account(after update) { // Perform SOQL query once. // Get the related opportunities for the accounts in this trigger, // and iterate over those records. for(Opportunity opp : [SELECT Id,Name,CloseDate FROM Opportunity WHERE AccountId IN :Trigger.New]) { // Do some other processing } }But, I do not quite understand the relationship between the fact that you can "unify" in one statement the for each and the SQL AND a potential "Benefit" to do this in terms of performance or efficiency.
What do you mean by "benefit of SOQL for loop"?
Thank you very much.
SOQL for loops can process records one at a time using a single sObject variable, or in batches of 200 sObjects at a time using an sObject list:
For example, the following code illustrates the difference between the two types of SOQL query for loops:
Please check below post for more infor
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_loops_for_SOQL.htm
Let us know if this will help you