Pass a List to the future method in Apex
You can unlock a lot of potential if you know how to pass a List (or map) to future method.
When Salesforce released future annotation method that was a boon to the developer community.
A lot of bottleneck scenarios that were not possible with Salesforce slowly started getting resolved because of @future annotation method.
One of my personal favourites is whenever we want to make a callout out of the box it's not possible using triggers unless we use @future annotation method.
But there is a major setback with future method, we cannot send Lists or Maps (complex data types) to future method and we cannot send SObject type params to future methods.
Basically, future methods accept only primitive datatypes.
In this post we are trying to understand how can we send List (or Maps) which are considered as complex data type to future methods.
One way of solving it is whenever we want to send List type data, we will try to convert that to JSON using JSON.Serialize()
method and we will try to send JSON string as a parameter to the future method.
In the future method also we will try to receive this as a string and then we will serialize it back to List data (or SObject).
Hope this is helpful!