I'm stuck at this error "Future methods do not support parameter type of Exception". Is there any workaround for this error?

  • Serialize to JSON and pass the String. – Jesse Milburn Oct 9 '18 at 15:47
  • @JesseMilburn Exceptions are not serializable. – David Reed Oct 9 '18 at 15:54

As @DavidReed mentions, future methods can only support primitive types and collections of primitive types. If you want to still pass in Exception classes or more complicated classes, use Queueable instead, which behaves almost exactly like future methods, but supports more complicated data types.

| improve this answer | |

This is part and parcel of the standard limitations on future methods:

The specified parameters must be primitive data types, arrays of primitive data types, or collections of primitive data types. Methods with the future annotation cannot take sObjects or objects as arguments.

You can pass an exception's message (e.getMessage()) to a future method, because it's a String, and String is a primitive type in Apex. Exceptions are not; they're objects. They also cannot be serialized to JSON, so you're stuck passing the exception's attributes to your future method.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.