You need to sign in to do that
Don't have an account?
Insert new record not working
Please help me. I am not sure what's the issue with this class its not updating.
Please help me!<
public class MyFirstClass { public static void method(){ List<Account> accLst = new List<Account>([select id,name,description from Account where name like 'United%']); system.debug('The account lists are:' + accLst); List<Account> accupdLst = new List<Account>(); for(Account acc: accupdLst ){ acc.Description = 'Updated from Apex Class'; accupdLst.add(acc); } if(accupdLst != null && accupdLst.size()>0){ update accupdLst; } system.debug('The updated account lists are:' + accupdLst); } }
Please help me!<
I want to tell you the thing you are doing wrong in your code.
You are trying to iterate accupdLst list which you have initialized but I can see that the list is empty and there are no records inside it.
All you have to do is replace accupdLst with accLst and now your code will surely execute because there you have made a query for this list
and so it contains records.
public class MyFirstClass {
public static void method(){
List<Account> accLst = new List<Account>([select id,name,description from Account where name like 'United%']);
system.debug('The account lists are:' + accLst);
List<Account> accupdLst = new List<Account>();
for(Account acc: accLst ){
acc.Description = 'Updated from Apex Class';
accupdLst.add(acc);
}
if(accupdLst != null && accupdLst.size()>0){
update accupdLst;
}
system.debug('The updated account lists are:' + accupdLst);
}
}
If you find this explanation helpful please mark it as best answer so others get help from this.
Thank you.
Ajay Dubedi
All Answers
I want to tell you the thing you are doing wrong in your code.
You are trying to iterate accupdLst list which you have initialized but I can see that the list is empty and there are no records inside it.
All you have to do is replace accupdLst with accLst and now your code will surely execute because there you have made a query for this list
and so it contains records.
public class MyFirstClass {
public static void method(){
List<Account> accLst = new List<Account>([select id,name,description from Account where name like 'United%']);
system.debug('The account lists are:' + accLst);
List<Account> accupdLst = new List<Account>();
for(Account acc: accLst ){
acc.Description = 'Updated from Apex Class';
accupdLst.add(acc);
}
if(accupdLst != null && accupdLst.size()>0){
update accupdLst;
}
system.debug('The updated account lists are:' + accupdLst);
}
}
If you find this explanation helpful please mark it as best answer so others get help from this.
Thank you.
Ajay Dubedi