• Sushmitha B 15
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
Hi,

We have a trigger which calls an static method specified with @future(callout = true) on every insert.

When creating records(insert) from  Schedulable batchclass  the following error occurs

First error: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, triggername: execution of AfterInsert

caused by: System.AsyncException: Future method cannot be called from a future or batch method:

Any solution for this please.

please find my batchclass sample here

 
global class SchedulableBatchClass implements Database.Batchable<sObject>, Schedulable,Database.AllowsCallouts
{
  global Database.QueryLocator start(Database.BatchableContext BC)
  {
    return Database.getQueryLocator( // query here);
  }
  
  global void execute(Database.BatchableContext BC, List<Contact> contacts)
  {
    for(Contact newcontact : contacts)
    {
       
                   
          INSERT newobject; // more than 1000 inserts
       
    }       
  }

  
  global void finish(Database.BatchableContext BC)
  {

  }
  
  global void execute(SchedulableContext SC)
  {
      SchedulableBatchClassFor sbc = new SchedulableBatchClassFor();
      Database.executeBatch(sbc, 600);
  }
}

//trigger
trigger tTrigger on t__c (after insert) 
{
    If(Trigger.isafter && Trigger.isInsert)
    {
      for(Integer i=0; i<trigger.new.Size();i++)
      {
        SomeClass.Staticmethod(trigger.new[i])  ;
      }
    }
}

public class someclass{
@future(callout= true)
    public static void ExecuteSend()
   {
//http request here.
}
}

Thanks.