1

I have a non future method that I use for before insert in criteria A, how can I use this method to a future method without copying the method and adding @future because I also need this for a particular criteria(criteria B) in after insert trigger event. Thanks

1
  • Put it in a public class and make the method public
    – cropredy
    Aug 27, 2017 at 3:05

1 Answer 1

7

Yes, you can call normal methods from a future method. Typically, when I need a method for multiple purposes, I'll write a future method that simply calls the non-future method.

@future public static void doSomethingAsync(Id recordId) {
    doSomething(recordId);
}
public static void doSomething(Id recordId) {
    // Do stuff
}

Note that because of the limitation of future methods, it's often necessary to requery the data that you need, so a more typical solution looks like this:

@future public static void doSomethingAsync(Id[] recordIds) {
    SObject[] records = [SELECT ... FROM ... WHERE Id = :recordIds];
    doSomething(records);
}
public static void doSomething(SObject[] records) {
    // Do stuff here
}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .