How do I mass update my object?

  • I have created a new number field within my Opportunities object which is set to required and has a default value (0), however this is causing issues with closed Opportunities that did not have the field present when editing them.

    I would have liked to simply do a mass update using SOQL, but as far as I'm aware we're cant do that. I would like to know what is the quickest/easiest way I can populate the records with this field empty with a figure?

    I do not want to install applications to do this, and I should note I have more than 2k records so I believe govern limits will effect the possible solutions.

    One solution I have tried is to create a trigger on before update, which would populate these fields if they are empty but this does not work, I believe the required attribute is kicking in before the trigger is.

  • Scott Pelak

    Scott Pelak Correct answer

    7 years ago

    For a one time update, try using the Execute Anonymous functionality in the Dev Console. There, one can write and execute Apex code. Note that all the governor limits are still in place (e.g. limit of 10,000 records in DML calls).

    Since you mention you only have 2,000ish records to update, Execute Anonymous will he handy.

    Example:

    List<Account> acctList = [SELECT Id, Name FROM Account LIMIT 2000];
    
    for(Account acct :acctList){
        acct.Name = acct.Name + ' super cool suffix';
    }
    
    update acctList;
    

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM