What would be the best way to touch all records in an object so that a trigger runs on each record? Is dataloader the best way or can this be achieve by a SQOL query or trigger?


  • update [select Id from Your_object__c where yourcriteria__c = true]; in case of huge amounts of records -- batch job with same code inside
    – kurunve
    Jul 31, 2016 at 8:55

2 Answers 2


For any reasonable size value, you need to either use the Data Loader, or use Batch Apex. I personally have a Batch Apex class that I use for this purpose, which I can call execute anonymous like so:

    new BatchProcess(
        new BatchRecordGenerator.FromQuery('SELECT Id FROM Lead'),
        new BatchRecordAction.UpdateRecords()));

This will be a feature in my open-source library when it's available. In the meantime, you should be able to figure out a basic way of doing this using interfaces. It really depends on what you need. My version will probably be far more involved than a simple answer here would satisfy.

That said, using the Data Loader is often effective. You can install/deploy the triggers to take care of "future" records, then query the records you need to update, then perform the update. The trigger should be able to take care of records created/updated after the deployment, and your data loader query can update those records that were not yet affected by the trigger.

If you know the value is less than 10,000 rows, and you won't exceed CPU limits, then a simple execute anonymous script will work:

update [SELECT Id FROM Lead WHERE ...];

You should always consider using Batch Apex when possible, because you don't have to leave your Data Loader running the entire time while it's running.

  • Just to confirm, updating the record in this manner without actually changing any field values will still cause workflows and triggers to fire? I've always set a "dummy" checkbox to true when updating via data loader, assuming that was necessary.
    – gorav
    Jul 31, 2016 at 17:05
  • Sfdcfox, Please let me know if your open-source library has feature for executing through batch.
    – Arun SFDC
    Oct 15, 2016 at 19:36
  • @ArunSFDC Yes, it includes a variation on this class, but it's not ready yet. My goal is to make a chainable system that allows multiple actions per execution.
    – sfdcfox
    Oct 15, 2016 at 20:04
  • @sfdcfox is it ready yet? ;)
    – ps2goat
    Oct 22, 2019 at 21:44

I just used the Salesforce Inspector extension for Chrome. This will do the batching for you with configurable options.

I Exported data using a query (specific to an object), then imported data the same way. You can click a button to copy the exported data and then paste it into the import screen. (Choose to Update the records!)

All you need to "touch" an object is the Id, so that's all I exported.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .