Question

I need to trigger updates of a whole bunch of records in a Salesforce database without really updating any values. This is to make a few formulas to recalculate some fields.

Here's what I tried - a schedulable class (say I want it to run every night):

global class acmePortfolioDummyUpdate implements Schedulable
{
    global void execute(SchedulableContext SC) 
    {
        for (Acme_Portfolio__c p : [Select Id From Acme_Portfolio__c]) {
            update(p);
        }
    }
}

update(p) is a DML statement and Salesforce limits the number of them to 150. In my case it's about a few thousands of records.

Also, I need to do this across many different portfolios. SF limits the number of scheduled classes to 10.

Any workaround for this? Thanks

Was it helpful?

Solution

Try Batch Apex. You can schedule Your batch using schedulable class. Correct me if I'm wrong but aren't formulas recalculated each time You read them?

Edit: Comment don't have enought space. I'm not guarantee this will compile (dont have access to org right now), but try sth like this:

global class batchClass implements Database.batchable<sObject>{ 
    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator('Select Id From Acme_Portfolio__c');    
    }   

    global void execute(Database.BatchableContext BC, List<sObject> scope){
        update scope;
    }
    global void finish(Database.BatchableContext BC){
    }   
}

And run this from system log:

Database.executeBatch(new batchClass());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top