If you are making Http Callouts, you have to use Scheduled Batch Apex. In Batch Apex, you can only make 10 callouts per call. Basically, you just pass 10 records at a time.
I dont have a link to a tutorial but here is sample code for the batch:
global class BatchSync implements Database.Batchable<sObject>, Database.AllowsCallouts {
public String query = 'Select ID, Name from Account';
global Database.QueryLocator start(Database.BatchableContext BC) {
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Account> records) {
String endpoint;
for ( integer i = 0; i< records.size(); i++ ){
try {
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
// Set values to Params
endpoint = 'Your endpoint';
req.setHeader('Authorization', header);
req.setHeader('Content-Type', 'application/json');
req.setEndpoint(endpoint);
req.setMethod('POST');
req.setBody('Information you wanna send');
req.setCompressed(true); // This is imp according to SF, but please check if
// the webservice accepts the info. Mine did not :P
// Had to set it to false
if (!Test.isRunningTest()) {
res = http.send(req);
String sJson = res.getBody();
System.debug('Str:' + res.getBody());
}
// now do what u want to with response.
}
catch (Exception e) {
System.debug('Error:' + e.getMessage() + 'LN:' + e.getLineNumber() );
}
}
}
global void finish(Database.BatchableContext BC){
}
}
You can use the records Account object to use any data from Accounts and even perform DML operations.
Basically, the above query should have more that 10 Accounts, but in order to make the callouts successful, you tell it do to 10 at a time like this:
BatchSync BS = new BatchSync();
Database.executeBatch(BS,10); // you can also do less than 10
Now you can put these above two lines in the Schedule class and schedule it for the time you want. Using the above method, you can process upto 50 million records in one session.