0

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

2
  • Serialize to JSON and pass the String. Oct 9, 2018 at 15:47
  • @JesseMilburn Exceptions are not serializable.
    – David Reed
    Oct 9, 2018 at 15:54

2 Answers 2

4

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.

3

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.

You must log in to answer this question.

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