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
Deepak Singh 116Deepak Singh 116 

First error: Too many future calls: 1

Please find my below batcjh class.In this batch i calling a future method from finish method which make a callout to external system.I read from the documentation that We can calll future method from finish method But while i call the future methid i get the error:
First error: Too many future calls: 1
global with sharing class errorinBatch implements Database.Batchable<SObject>,Database.stateful {
global set <String> log;
global database.QueryLocator start(Database.BatchableContext bc){
string query='select id,name,Description,CurrentGenerators__c from opportunity';
system.debug(database.getQueryLocator(query));
return database.getQueryLocator(query);
}
global void execute(Database.BatchableContext bc,List<SObject> scope){
System.debug(scope);
System.debug('====>>>>>'+scope.size());
//List<Opportunity> opp=new List<Opportunity>();
if(scope.size()>0){
for(Opportunity op:(List<Opportunity>)scope){
System.debug(op.Name);
op.Description=op.CurrentGenerators__c;
// opp.add(op);
}
}
database.SaveResult[] result=database.update(scope,false);
System.debug('====>Result'+result);
Integer rsize=result.size();
for(integer i=0;i<rsize;i++){
System.debug('for loop Block');
System.debug('====>Result[0]'+result[0]);
System.debug('=====>'+i);
System.debug('+++++>>'+scope[i].Id);
if(!result[i].isSuccess()){
log=new Set<String>();
log.add('Error in Opportunity'+scope[i].Id+'Error Message'+result[i].getErrors()[0].getMessage());
System.debug(log);
}
else {
system.debug('+++++>>> updated successfully');
}
}
}
global void finish (Database.BatchableContext bc){
Future_Schedule_Call_Example.show('cdeeuhwidhi');
}
}

Please help.

Thanks,
Deepak​​​​​​​
Khan AnasKhan Anas (Salesforce Developers) 
Hi Deepak,

Greetings to you!

Please refer to the below links which might help you further with the above issue.

https://salesforce.stackexchange.com/questions/160400/system-limitexception-too-many-future-calls-1-in-batch-finish

https://salesforce.stackexchange.com/questions/57154/calling-future-method-from-batch-class

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas