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
anil.a1.3940255032549827E12anil.a1.3940255032549827E12 

Which is the best way to update list of records?

scenario 1 :
list<account> acc = [select id,name,Counter__c from account ];
for(account a : acc)
{
a.Counter__c = 'testCounter';
}
update acc;

scenario 2:

list<account> acc1=new list<account>();
list<account> acc = [select id,name,Counter__c from account ];
for(account a : acc){
a.Counter__c = 'testCounter';
    acc1.add(a);
}
update acc1;
sachin_dreamoncloudsachin_dreamoncloud
Offcourse first scenario. Always reduce the number of variable declaration which adds on to the heap size, when you can acheive with the minimum.
To understand more go to this link (http://blog.jeffdouglas.com/2010/08/16/managing-the-heap-in-salesforce-com/).