function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ashritha ReddyAshritha Reddy 

hii

how can we make the callouts in batch apex?
AnjithKumarAnjithKumar
Hello Ashritha,

You have to implement the batch class with Database.AllowCallouts Interface as shown below. 

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

For more info. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm

Hope it helps you.

Thanks,
Anjith
cloudSavvyProgcloudSavvyProg
Hi Ashritha,

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
 
Piyush Kumar 58Piyush Kumar 58
Hello Ashritha,

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){

   }

}

Thanks.