function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sf@sfsf@sf 

Scheduler - Approach

Hi,

I need to design a Scheduler which runs Every day at 5 PM.

 

which fires a Batch Apex Which Pulls up All records nearly 40,000 ac based on filter logic and ordered by created date.

Filter logic is between Record Created dates Example : 1-JAN-2012 to 31-MAR-2012

 

My limitations are only to process 3000 Records per day should be processed. 

 

so on the next scheduled job it should start from the next 3000 records

 

and the requirement is to process 3000 records every day with a new set of records. which means the same records shoulf

 

Best Answer chosen by Admin (Salesforce Developers) 
Saikishore Reddy AengareddySaikishore Reddy Aengareddy

Here is what I understood from your posting..

 

You wanted to process only 3000 Account records every day and once processed those should not be processed again right? 

If yes.. then

1. create another Boolean field on Account something like processed

2. In your query include another filter called processed__c=false

(select Id, name from Account where <DateRange condition> AND processed__c=false orderby createdDate Desc/Asc LIMIT 3000)

3. Once you processed make sure you update all of those 3000 records with a flag processed__c = true.

 

This way you will be querying only unprocessed records everyday..

 

 

 

All Answers

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

Here is what I understood from your posting..

 

You wanted to process only 3000 Account records every day and once processed those should not be processed again right? 

If yes.. then

1. create another Boolean field on Account something like processed

2. In your query include another filter called processed__c=false

(select Id, name from Account where <DateRange condition> AND processed__c=false orderby createdDate Desc/Asc LIMIT 3000)

3. Once you processed make sure you update all of those 3000 records with a flag processed__c = true.

 

This way you will be querying only unprocessed records everyday..

 

 

 

This was selected as the best answer
sf@sfsf@sf

Thanks Sam,

Thats the best approach i would look forward to implement , but Adding a field to account object is not accepted by orgs since its just  a temporary process. i also tried creating a custom object to store the date of the last Created datetime of processed record and on the next schedule start it from there(iie 3000th record created date) but could not convice.

 

can store a value some where without using Objects and retrive it for the next schedule. i am being unrealistic but. 

unlike java we can store a value in context variable and retrive it through out the application. so i am just wondering,

if there is there any other alternative. Appreciate your response.

 

 

 

kibitzerkibitzer

Sam's suggestion is a good one.

 

There is no "application context" that persists. If you can manage with storing just the date of the last processed object, you could use a custom setting.

I suppose you could sore the date on an external web site via a web service call. It would eliminate the need to store the information in Salesforce, but sure is a costly and complex solution for a simple problem.

Or, if they really don't want to add any fields or objects, you could do a cheat - create a lead, task or some other object that won't be used or impact the business process, and just hide your last processed date in that object (and hope nobody finds it and deletes it).

 

It's a kludge, but it sounds like somebody is tying your hands in a way that is somewhat unrealistic.

 

Good luck

 

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

If you have privilage of creating a new object then in that object create a new text field which stores only the processed records ID's.

 

Step1: In your custom object create a text field something like Processed_Account__c which will have the Id's of the processed Accounts

Step2: Query the custom object and prepare a set of Processed Account Id's.

step 3: In your query

(select Id, name from Account where <DateRange condition> AND Id NOT IN :(step 2 set) orderby createdDate Desc/Asc LIMIT 3000)

step4: After processing insert all the processed accounts id's into the custom object.

sf@sfsf@sf

Thanks Sam, kibitzer,

I Got it working with Custom Object Approch as suggested. 

had it been the Decission of mine i would go with the Sams First Approach creating a field in Accounts as kibitzer mentioned it right. Studying its being unrealistic.

 

Thanks for your valuble time.