I'm currently working with a customer that is interested in launching Salesforce Batch jobs from an external scheduler. I was thinking about the following
- Create a global interface
global interface TWSJob {
void execute();
}
- Create a RESTful web service
@RestResource(urlMapping='/TWSSubmitApexClass/*')
global with sharing class TWSSubmitApexClass{
@HttpGet
global static void doGet() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String apexClass = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
Type t = Type.forName(apexClass);
TWSJob s = (TWSJob)t.newInstance();
s.execute();
}
}
- Create a RESTful web service (/TWSMonitorAPEXJob) to monitor the progress using AsyncApexJob.
What do you guys think?
Many thanks.
Miguel