How can i bulk update Accounts in Salesforce?

222 Views Asked by At

I am trying to update the Description for over 200 Account entities by matching on Salesforce Id. I am using the following trigger ,

 Trigger MyNew_tr_U on Account (after update) {
 set<ID> ids = Trigger.newMap.keyset(); 
 for(ID id : ids) 
 {
   newChangeTable__c ch = new newChangeTable__c();
   ch.Status__c = 'update'; 
   ch.Url__c = id; 
   ch.Process__c = false; 
   insert ch;
 }

}

but when i do the data Import of the csv file i get the following error:

  CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY:MyNew_tr_U: execution of AfterUpdate
  caused by: System.DmlException: Insert failed. First exception on row 0; first error: 
  STORAGE_LIMIT_EXCEEDED, storage limit exceeded: []

How can i get the trigger to work ?

Further to @eyescream answer below. What if I have no filter as in Name, that gives the same error.

Trigger MyNew_tr_U on Account (after update) { List<newChangeTable__c> toInsert = new List<newChangeTable__c>();

for(Account a : trigger.new){
    Account old = trigger.oldMap.get(a.Id);
    toInsert.add(new newChangeTable__c(
            Status__c = 'update',
            Url__c = a.Id,
            Process__c = false
        ));        
}
insert toInsert;

}

1

There are 1 best solutions below

8
eyescream On

You're running out of database space. Go to Setup -> Storage Usage and have a look. Maybe you can delete something, maybe (if it's production) you can buy more storage from SF (there are "data packs" 10 GB each or you get some more storage with every user license you buy). That works only in productions, sandboxes have fixed size though so your only way is to delete some old stuff.

As for the trigger itself...

  • you'll want to bulkify it, move the insert statement out of the loop
  • you'll probably want to run it only if some key fields actually changed, not on every edit that doesn't change anything?
  • this can blow your storage space very quickly, consider using standard field history tracking table (optionally with FAT, paid extra) or maybe store the data in "Big Objects" rather than just normal custom object

Something like this, it inserts your thing only if Name changed.

Trigger MyNew_tr_U on Account (after update) {
    List<newChangeTable__c> toInsert = new List<newChangeTable__c>();

    for(Account a : trigger.new){
        Account old = trigger.oldMap.get(a.Id);
        if(a.Name != old.Name){
            toInsert.add(new newChangeTable__c(
                Status__c = 'update',
                Url__c = a.Id,
                Process__c = false
            ));
        }
    }
    insert toInsert;
}