Whenever a case is updated by an agent, a batch job posts the new values to external system. With the new flex queue, we can have upto 100 jobs in holding and 5 in processing/ preparing. We have tested batch job and it is efficiently running even for large quantities of data loaded in a single instance.
I got chaining in batch class so once the batch class is instantiated, it can handle even large amounts of data. But my concern is: My organization has around 1500 case representatives. I am trying to handle the following scenario: In any situation lets say all these agents update their cases individually which means 1500 batch jobs, right ?
I went through this link tried to add schedulable interface to my class and wondering if this will help me. Reason why I am not sure if this works or not is because I can load 100000 cases from data loader which splits into batches of 200 i.e., 50 batches and as I said my batch job is able to handle any number of cases loaded in single instance. But to test the above scenario, I need some ~500 agents updating their respective assigned case at almost the same time.
Code:
global class postClass /*implements Schedulable*/ {
public void caseUpdate(list<case> c){
//list of cases matching specific criteria
}
public string buildCaseString(case c){
//builds a json case string for case c
}
public static void postCases(list<case> cList){
List<string> postList = new List<String>();
for(case c : cList){
String postBody = buildCaseString(c);
postList.add(c);
}
if([SELECT count() FROM AsyncApexJob WHERE JobType = 'BatchApex' AND Status = 'Holding')] < 100){
Database.executeBatch(new caseBatch(postList));
} else {
//not sure if below code works
postClass sc = new postClass();
Datetime dt = Datetime.now() + (0.024305); // i.e. 30 mins
String sch = dt.format('s m H d M \'?\' yyyy');
String jobID = system.schedule('Another Job', sch, sc);
}
}
}
Any other ideas, please let me know.
Thanks.