+ Start a Discussion
BomanBoman 

One-time processing of 200K Objects: Scheduler, Bulk API, or other?

Here's my situation: I've got approx. 200K Accounts/Customers in my SFDC instance, and now need to calculate and assign a LCV (Lifetime Customer Value) to each of these. I've got the individual metrics and the LCV function defined. The plan is apply computeLCV() "one-time" to every existing customer in order that I have this value for all Accounts. Then, on an on-going basis I would use a "after update" trigger to re-calc LCV if any of the metric-bearing field change. Straightforward!

 

But, I'm not sure what's the correct approach to the handle the "one-time 200K Account" calculateLCV processing!! Should I:

 

1> Use scheduled Apex:

global class calculateLCV implements Schedulable { 
 global void execute(SchedulableContext ctx) {
 // Query/retrieve and calculate LCV for all 200K existing Account}

I could then schedule this job to run just once! After a successful run, delete it!

 

2> Use the Bulk API to extract and process the 200K Accounts

 

3> Some other alternative e.g. regular Apex, invoked via a button click to do the same thing (and later removed), or Anonymously execute some Apex code to achieve the desired calculation, etc.

 

Thanks for your suggestions!

Best Answer chosen by Admin (Salesforce Developers) 
Cory CowgillCory Cowgill

Batch Apex is specifically designed for this use case. Look at the Batch Apex section of the Developer Guide which has all the informaiton you'll need and a sample code provided: http://www.salesforce.com/us/developer/docs/apexcode/index.htm

 

In short:

 

1. Build a Batch Apex class to handle the Logic.

2. Execute the Batch Apex class from an Anonymous Apex Context (System Log or IDE).

 

 

All Answers

jwhartfieldjwhartfield

We have done similar things before with our product.  Generally, we use option #1 (make a batch job).  But we leave the batch job there just in case bad data creeps in and then it can be run anytime.

 

Once difference I noticed between our solution and yours is that we don't bother to use a schedulable class.

Cory CowgillCory Cowgill

Batch Apex is specifically designed for this use case. Look at the Batch Apex section of the Developer Guide which has all the informaiton you'll need and a sample code provided: http://www.salesforce.com/us/developer/docs/apexcode/index.htm

 

In short:

 

1. Build a Batch Apex class to handle the Logic.

2. Execute the Batch Apex class from an Anonymous Apex Context (System Log or IDE).

 

 

This was selected as the best answer
BomanBoman

Ok. I'm using Batch Apex and a Trigger to achieve this. Thanks.