How to touch all records in an object to run a trigger?

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?

Thanks

Replay

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:

Database.executeBatch(
    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.

Category: salesforce crm Time: 2016-07-31 Views: 4

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.126 (s). 12 q(s)