Entry point for Synchronous and Asynchronous methods
- johnsontitus
- May 26, 2020
- 1 min read
public with sharing class futureexperiment {
private static Boolean futuresent = false;
public static void test2()
{
//entry point for synchronous method call
//call it within the future call context
if(System.isFuture() || system.isBatch())
{
test2sync();
return;
}
//immediately return if the future call is already made
if(futuresent) return;
//else flag the static variable before making the future call
futuresent = true;
//entry point for future call
//when not in the future call context
test2future();
}
@future
public static void test2future()
{
test2sync();
}
public static void test2sync()
{
system.debug('performing operation sync or async');
}
}

Comments