[SalesForce] Can Process Builder run @future methods

We're hitting CPU Time Limit Exceeded issues with a class that's being called by a Process Builder.

From the SF solutions page, it was noted that one fix for CPU Time Limit Exceeded is to make the code asynchronous by adding the @future tag.

So what we did is that the Process Builder calls an @invocablemethod and that method calls a @future method. The class compiles so I assume it might work.

However, are there any issues that might be encountered with a Process Builder calling an invocable method calling a @future method?

Thanks.

Best Answer

The only main problem you should be aware of is that your process builder must not call the future method recursively. This would happen because the future method performs some sort of DML operation (usually an update) that causes the process builder to fire again, and calling the future method while already in a future context. As long as you remember to build your criteria properly, or avoid recursively calling your method, you should be okay.

In your invocable method, you can:

if(!System.isFuture()) {
    callFutureMethod();
}

To avoid the potential for infinite recursion.