Yes, we can make callouts in batch apex. But we need to be aware of some constraints/limits.
This line is from salesforce doc: To use a callout in batch Apex, specify Database.AllowsCallouts in the class definition. For example: global class SearchAndReplace implements Database.Batchable<sObject>, Database.AllowsCallouts{ }
Here are some doc to give you more info: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm
Yes, batch apex class allow us to make callout. You must add Database.AllowsCallouts in your batch class. You can write callout method in the start section.
public with sharing class BatchCallout implements Database.Batchable<sObject>,Database.AllowsCallouts,Database.Stateful{
public Database.QueryLocator start(Database.BatchableContext bc) {
}
public void execute(Database.BatchableContext BC, list<sObject> scope){
// write here to callout method
}
public void finish(Database.BatchableContext BC){
}
}
You have to implement the batch class with Database.AllowCallouts Interface as shown below.
For more info. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm
Hope it helps you.
Thanks,
Anjith
Yes, we can make callouts in batch apex. But we need to be aware of some constraints/limits.
This line is from salesforce doc:
To use a callout in batch Apex, specify Database.AllowsCallouts in the class definition. For example:
global class SearchAndReplace implements Database.Batchable<sObject>,
Database.AllowsCallouts{
}
Here are some doc to give you more info:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm
https://developer.salesforce.com/forums/?id=906F00000008yOuIAI
http://salesforce.stackexchange.com/questions/19444/batch-apex-with-webservice-callout
http://salesforce.stackexchange.com/questions/15605/http-callouts-in-batch-apex
There are lot of discussion around this topic already in developer community.
Dont forget to read the limitations.
Hope this helps.
Regards,
CloudSavvyProg
Yes, batch apex class allow us to make callout.
You must add Database.AllowsCallouts in your batch class.
You can write callout method in the start section.
Thanks.