0

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;

}

Abbey
  • 153
  • 2
  • 11

1 Answers1

1

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;
}
eyescream
  • 18,088
  • 2
  • 34
  • 46
  • Still fails with the error CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY. If i use future calls i think it will process the data successfully , but i dont want future calls method. Is there another way of doing this without future calls ? – Abbey Mar 03 '22 at 19:32
  • In my case i had 200 Accounts where the Description of all 200 changed via a Bulk Import. I have added extra information to the question – Abbey Mar 03 '22 at 19:34
  • well, did you investigate setup -> storage usage? Deleted some data to make room? – eyescream Mar 03 '22 at 20:53
  • this is what i dont understand , if use a future call , @future (callout=true) by calling another class in my trigger it works just fine , and thats without clearing storage ? – Abbey Mar 03 '22 at 21:10
  • I have checked the data storage , i am over by 2MB , but i cant just do a mas delete or clear objects as i need these, so do i need to purchase more storage for your solution to work , but with future calls it seems to work without having to increase storage ? – Abbey Mar 03 '22 at 21:20
  • Future cheats a bit by running in some system context but I wouldn't count on it. Depending on how fast SF calculates some statistics and catches up... Once I got to 128% as sysadmin (mortals were blocked earlier) before it completely froze over. And well... if the future fails user won't know (admin can check in setup -> jobs but that's it). If this is your field tracking solution do you want to have complete history or not? Will you sacrifice tracking just to complete the account save? You'd achieve same with `Database.insert(toInsert, false);` without future... – eyescream Mar 03 '22 at 21:32
  • So the example you gave above should work if i get back some storage... or do i use the Database.insert(toInsert, false);.. sorry just started with all of the SF stuff .. get to know it all. Also just curious im not actually creating anything , the entries are already there , im just modifying ? – Abbey Mar 03 '22 at 22:40
  • Yes, it'd work if you had free storage. Future is a bit of a hack plus well, it's a "Congratulations, as sysadmin you can still edit the data but your non-admin users are completely blocked" situation. Have you really solved anything ;) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_database.htm - if you want accounts to save ok and history table optionally - Database... methods would be a way to do it without @future. – eyescream Mar 04 '22 at 08:29