Calling future method from Batch

I have a requirement where a future method need to be called from batch apex ,I came across various articles stating that a future method could not be called from the batch.
Is there any alternate solutions for that?

Answer

UPDATED ANSWER

(not batch but…).

I was investigating the ScheduledDispatcher: https://gist.github.com/gbutt/11151983

And lo and behold this works:

global class ScheduledDispatcher Implements Schedulable{

    public Interface IScheduleDispached{
        void execute(SchedulableContext sc);
    }

    global void execute(SchedulableContext sc){
        Type targetType = Type.forName('{HANDLERNAME');
        if(targetType != null){
            IScheduleDispached obj = (IScheduleDispached)targetType.newInstance();
            obj.execute(sc);
        }
    }


}

public class {HANDLERNAME} implements ScheduledDispatcher.IScheduleDispached {

  public void execute(SchedulableContext sc)
    {

        //Call your Future Method Here

    } 

}

If you still need to do it from within the batch context you can do as previously suggested:

public static method1(){

   method2();

}

@future
public static method2(){

}

call method1 from the batch and method2 from elsewhere

Attribution
Source : Link , Question Author : Manoj Chandran , Answer Author : Eric

Leave a Comment