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
Jagadish LutimathJagadish Lutimath 

how to invoke one class future method in another apex class?

Hi Everyone,

I have written an apex class which has a future method. As of now, I am invoking that class method through triggers and it is working as expected. Here my requirement is, we have a helper class and I need to invoke the future method through the helper class. Can anyone let me know how to invoke the future method from helper class? 

Appreciate any help.
Dayakar.DDayakar.D
Hi Jagadish Lutimath,

We can directly call future method using its class name.future method name.

please find example.
 
public with sharing class WarehouseCalloutService {
@future()
    public static void runWarehouseEquipmentSync(){
//Some code here.....
    }
}

another apex class
***********************************
public class Maintenance{
 public static void callingFuture()
{
     WarehouseCalloutService.runWarehouseEquipmentSync();
}

}

Please let me know, if it helps you.

Best Regards,
Dayakar.D
Jagadish LutimathJagadish Lutimath
Hi Dayakar, I have passed the collection of opportunity Ids, and code has written DML operation for order line Item object
01 public with sharing class WarehouseCalloutService {
02 @future()
03  public static void runWarehouseEquipmentSync(Set<id> OppIds){
04  //Some code here.....
05    }
06 }
07 
08  another apex class
09  *****************************
10  public class Maintenance{
11  public static void callingFuture()
12  {
13     WarehouseCalloutService.runWarehouseEquipmentSync();
14  }
15 
16}
Jagadish LutimathJagadish Lutimath
Hi Dayakar.D, I have passed the collection of IDs which are related to Opportunity and My code will Invoke on DML operation of Order line Item object (Roll Up from Oredr Line Item[Child] to Opportunity[Parent]) public with sharing class WarehouseCalloutService { @future() public static void runWarehouseEquipmentSync(set OppsId){ //Some code here..... } } another apex class *********************************** public class Maintenance{ public static void callingFuture() { WarehouseCalloutService.runWarehouseEquipmentSync(); } } *Regards,* *Jagadish Lutimath* *SFDC Developer Analyst*
Dayakar.DDayakar.D
Please try like below.
 
public with sharing class WarehouseCalloutService {
@future()
    public static void runWarehouseEquipmentSync(Set<Id> OpportunityIds){
//Some code here.....
    }
}

another apex class
***********************************
public class Maintenance{
 public static void callingFuture()
{
   //1.get the opportunity ids 
   //2.Assign your ids to var
    set<id> OppIds= ........//assign
//pass them to your future method
     WarehouseCalloutService.runWarehouseEquipmentSync(OppIds);
}

}

 
Jagadish LutimathJagadish Lutimath
Thanks for the replies. I found it:) *Regards,* *Jagadish Lutimath* *SFDC Developer Analyst*