function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KuenKuen 

Mass Update for existing data

Hey all,

 

I have a trigger in place that changes a custom field in account to auto fill a value if nothing exists. However, this only affects new/updated accounts... How would I do this for existing accounts? How could I activate the trigger to affect all accounts OR is there a better way to mass update existing 'blank' data?

 

I tried to create a trigger to view all 3000 accounts, however I reached limits so I couldn't do a simple after update/after insert trigger that just selects all accounts and edits the value and updates it. Here is the code,

 

 

trigger Run_Once_To_Fix on Account (after insert, after update) {
    list<Account> accs = [SELECT Id, Name, Zendesk__Zendesk_Organization__c 
        FROM Account WHERE Zendesk__Zendesk_Organization__c = '' LIMIT 100];
    
    for (Integer i = 0; i < accs.size(); i++)
        {
            accs[i].Zendesk__Zendesk_Organization__c = accs[i].Name;
        }
    
    if (accs.size() > 1) {
        update accs;
    }
}

 

 

Any ideas on how I can achieve what I want it to do?

 

Thanks

 

Kuen

Jeremy_nJeremy_n

One possibility is to use Eclipse's Anonymous Apex function to run your code. Be careful, it would be easy to do something you don't want to do.

 

Another option is to just pull the data out through the data loader or Excel Connector, and update it manually. If all you're doing is copying the Name into your other field, this would be easy to do in Excel, then just do a mass update.

 

Jeremy

hisrinuhisrinu

You just need to change the trigger and run the dummy update with the help of data loader where that field is null.

 

 

trigger Run_Once_To_Fix on Account (before insert, before update) {  
for (Account a : Trigger.New)
if(a.zendesk__zendesk_organization__c == null)
a.Zendesk__Zendesk_Organization__c = a.Name;//This line
}