You need to sign in to do that
Don't have an account?

CPU time limit exceeded
I have the following code that get 'Apex CPU time limit exceeded'
List<USER> userList = new List<USER>();
for (USER aUser : [SELECT u.city, u.id FROM User u where u.state = 'NEW YORK'] ) {
aUser.city = 'New York';
userList.add(aUser);
}
update userList;
Per recommendations below:
// Use this format for efficiency if you are executing DML statements // within the for loop. Be careful not to exceed the 150 DML statement limit. Account[] accts = new Account[];
for (List<Account> acct : [SELECT id, name FROM account WHERE name LIKE 'Acme']) {
// Your logic here
accts.add(acct);
}
update accts;
, I revised the query as follows
List<USER> userList = new List<USER>();
for (List<USER> user : [SELECT u.id FROM User u where u.state = 'NEW YORK']) {
...
userList.add(user);
}
but get this error:
Method does not exist or incorrect signature: void add(List<User>) from the type List<User>
Please tell me why. thanks a lot
List<USER> userList = new List<USER>();
for (USER aUser : [SELECT u.city, u.id FROM User u where u.state = 'NEW YORK'] ) {
aUser.city = 'New York';
userList.add(aUser);
}
update userList;
Per recommendations below:
// Use this format for efficiency if you are executing DML statements // within the for loop. Be careful not to exceed the 150 DML statement limit. Account[] accts = new Account[];
for (List<Account> acct : [SELECT id, name FROM account WHERE name LIKE 'Acme']) {
// Your logic here
accts.add(acct);
}
update accts;
, I revised the query as follows
List<USER> userList = new List<USER>();
for (List<USER> user : [SELECT u.id FROM User u where u.state = 'NEW YORK']) {
...
userList.add(user);
}
but get this error:
Method does not exist or incorrect signature: void add(List<User>) from the type List<User>
Please tell me why. thanks a lot
for (USER> u : [SELECT id FROM User where state = 'NEW YORK'])
Please check once following code :
Hope this helps you!
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
List<USER> userList = new List<USER>();
for (USER user : [SELECT u.id FROM User u where u.state = 'NEW YORK']) {
...
userList.add(user);
}
Kindly mark my answer if it helps you.
Thanks,
Hasan Shamsi