+ Start a Discussion
Jin Kaur 7Jin Kaur 7 

Run a mass edit to trigger Workflows

Hello,

Could anyone help me on how I get a mass edit on All Accounts which have a Status e.g. Customer.  I have serveral Workflows which need to run daily for these Customers.  However, the records need to be edited for the WF to trigger.

I'm not apex efficient and am not sure how to go about getting this done. 

 

I have seen this:  

in your developer console run the query. suppose your object is account.
List<Account> acc = [Select id from account limit 10000]; update acc

 

From this link: http://salesforce.stackexchange.com/questions/93434/trigger-a-mass-record-update-to-activate-workflow

But I am not sure where to start this?  Can anyone guide me please.

Thank you
Jin

Best Answer chosen by Jin Kaur 7
EmilienGuichardEmilienGuichard
Just add a where clause to your SOQL query :
List<Account> acc = [Select id from account where account_status__c = 'Customer' limit 10000]; 
update acc;

 

All Answers

EmilienGuichardEmilienGuichard
Hello,

You can run code directly from the Developer Console (menu under your name) and go to Debug > Open Execute Anonymous Window

Otherwise a more effective to automatize this could be to run a daily batch (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm
Jin Kaur 7Jin Kaur 7

Hi Emilien,

I did what you said and pasted the code in the window:

List<Account> acc = [Select id from account limit 10000]; update acc

 

I got an error:

Line: 2, Column: 0
expecting a semi-colon, found '<EOF>'

EmilienGuichardEmilienGuichard
You need to add ";" after update acc
Jin Kaur 7Jin Kaur 7

Ah Great thanks, lastly, how do i write so that i only want it to run on accounts that have the custom field marked as Customer

So, Account_Status__c is "Customer"

Jin Kaur 7Jin Kaur 7
Because I get an error on it as it's only become a required field recently and there are some blank records
EmilienGuichardEmilienGuichard
Just add a where clause to your SOQL query :
List<Account> acc = [Select id from account where account_status__c = 'Customer' limit 10000]; 
update acc;

 
This was selected as the best answer
Jin Kaur 7Jin Kaur 7
Thank you that worked :)
Jin Kaur 7Jin Kaur 7

Hi Emilien,
I tried the same format for Contacts with this in the criteria

List<Contact> con = [Select id from contact where Main_Contact__c=TRUE]; update con;

but this is giving me an error of

Line: 6, Column: 1
System.LimitException: Apex CPU time limit exceeded