if you want to update bunch of the records with specific fields, you can use this. Example scneario is below to update account name records with testname.
list<account> lstaccount = [select id,name from account limit 100]; list<account> lstadd = new list<account>(); for(account acc:lstaccount) //lstaccount have first 100 records from the account object and iterate 1 by one { acc.name = 'testaccount-updated'; lstadd.add(acc); } update lstadd;
You are passing the values present in st1(being a list of records) to st object instance one at a time when the for loop is executed.
All Answers
You are passing the values present in st1(being a list of records) to st object instance one at a time when the for loop is executed.
list<account> lstaccount = [select id,name from account limit 100];
list<account> lstadd = new list<account>();
for(account acc:lstaccount) //lstaccount have first 100 records from the account object and iterate 1 by one
{
acc.name = 'testaccount-updated';
lstadd.add(acc);
}
update lstadd;