4

I just wondering if someone could guide me to a document of how to perform Apex scheduled job – To call .net web service hosted in IIS of external server on a periodic basis. My requirement is every 30 mins my Apex scheduled Batch job to call .net webservices hosted in IIS and update respective fields in Account object with resultset recieved from the Remote Call. I dont have the Webservice Up yet but I am trying to find an example on how the whole integration is done. Is it possible? Can any one guide me out in the integration part?

3

You'll need to write some Apex to make the callout to IIS. Whether this happens via Apex to WSDL generated code, writing a simple class to call a REST service, or using outbound messaging perhaps depends on your IIS web service.

Assuming you have the webservice code already in place, you'll need a few things to schedule the callouts

  1. A scheduled class that calls a batch job.
  2. A batch job, which implements Database.AllowsCallouts (See: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm)
  3. The batch job will likely call another Apex class that performs the callout to your web service.
  4. Once your code is in place, you can schedule it to run through the "Schedule Apex" button on the Apex Classes list view in Salesforce.

Batch jobs cannot call future methods, but can make callouts if they implement Database.AllowsCallouts.

Furthermore, you are limited to 10 callouts per batch. For instance, if your webservice only supports one record per request, you'll need to restrict the batch size in your scheduled Apex to 10.

Your schedule class might look similar to the following:

global class myscheduleclass implements Schedulable {
    global void execute(SchedulableContext sc) {
        //10 denotes my batch size, if you can afford 200 records, then remove second parameter
        Database.executeBatch(new mybatchclass(),10);
    }
}

Your batch class might look like:

global class mybatchclass implements Database.Batchable<sObject>,Database.AllowsCallouts    {

    global mybatchclass() {}

    global List<sobject> start(Database.BatchableContext BC) {
        //Query for your records here
    }

    global void execute(Database.BatchableContext BC, List<sobject> scope) {
        //Call your class that executes the IIS callout here
    }

    global void finish(Database.BatchableContext BC) {
        //chain other batch processes if need be here
    }
}

That should help get you started.

1
  • Thank you Mr.James.This will be very helpful for my work. Will work on that one.
    – Arun
    Mar 18 '14 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.