3

Attempted to set a value to a field of the account object across 70000 records using anonymous apex execution causes below exception;

System.LimitException: Apex CPU time limit exceeded

This is the code I tried,

List<Account> accts = [SELECT Id, EMP_number__c, SOCIAL_Number__c FROM Account WHERE EMP_number__c != null ];
for (Account a : accts) {
    a.SOCIAL_Number__c = a.EMP_number__c;
}
update accts;

How could I set this EMP_number__c TO SOCIAL_Number__c through-out 70000 records?

0
3

Use data loader

  1. Export ID and those two fields
  2. Copy EMP_Number__c and paste column with the data to a new column
  3. Rename new column to `Social_Number__c'
  4. Update into salesforce

Since you should have hit the DML or Query Rows governor limits before the CPU timeout it sounds like you have some process that take a lot of time. If everything was working efficiently.

if Using Dataloader you still hit CPU timeout limits you could

  • Reduce the batch size from 2000 down to say 100
  • Keep reducing until you get it to work (should not go below say 50 but can go lower if needed)
  • NEVER reduce it to 1 in this case as you will kill your API Request Limits
2
  • I've worked at places where we had to set the batch size to 10, because anything more than that would CPU timeout. It really just depends on how many triggers and so on you have going on. – sfdcfox Dec 11 '15 at 2:53
  • agreed (but more typical code is inefficient I would think). I have also made the mistake of setting it to 1 because 10 did not work. Took down the integrations for almost 3 hours because hit API limits. Luckily they had premier support and were able to get it raised – Eric Dec 11 '15 at 2:58
2

If you choose to use execute anonymous, you can't process all the records at once. There's governor limits that would prevent you from updating more than 10,000 rows at once anyways. You'll have to come up with some way of selecting new records each time. You could probably do this:

List<Account> accts = [SELECT Id, EMP_number__c, SOCIAL_Number__c FROM Account WHERE EMP_number__c != null AND SOCIAL_Number__c = NULL LIMIT 10000];
for (Account a : accts) {
    a.SOCIAL_Number__c = a.EMP_number__c;
}
update accts;

Every time it times out, simply reduce the LIMIT by half until it doesn't fail, then just run it over and over again until you're done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.