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
Shephali SwarnkarShephali Swarnkar 

help to understand the following code execution

if I have 2430 opportunity. for how many times each LOC will execute and why?
and how it will solve the Heap size and DML issues.

1. for (List<Opportunity> Opps : [SELECT Id FROM Oportunity]) {
2.    for (Contact opp : Opps){
3.        // Modify opp
4.    }
5.    Database.update(Opps, false); 
6. }

 
MagulanDuraipandianMagulanDuraipandian
Shephail,

1. Inside the loop DML should be removed.
2. At line number two, you cannot iterate opps with Contact.

Code is incorrect.
Shephali SwarnkarShephali Swarnkar
if I have 2430 opportunity. for how many times each LOC will execute and why? and how it will solve the Heap size and DML issues.
 
1. for (List<Opportunity> Opps : [SELECT Id FROM Oportunity]) {
2.    for (Opportunity opp : Opps){
3.        // Modify opp
4.    }
5.    Database.update(Opps, false); 
6. }

Here in this code sample, line1 will run forr 1time and it will fetch all 2430 records. If there are 10,000 records or say even more then too line 1 will execute for 1 time. so in such case how it will handle the HeapSize limit?