It was a relief when Salesforce had come up with
There were some bottlenecks that
@future was solving and soon it also started showing its age (drawbacks :p). I will save that for another day, maybe.
The bottom rule is, we will convert Synchronous Apex to Asynchronous Apex using
@future annotation which is one of the variants of Asynchronous Apex that Salesforce provides.
Advantages of @future annotation
- We can make a callout from Trigger using
- When there are
CPU time limit exceptionsand
SOQL 101 Exceptionswe can use
@futureand push the business logic that's not of that priority to get executed in Asynchronous mode.
- We can increase the request timeout using
- Scenarios like deleting a record on click of a checkbox and updating a record can only be configured using
Drawbacks with @future annotation
- We cannot invoke a future method within another @future method
- Future methods cannot be used in Batch Apex.
- @future method cannot return any data back.
- We cannot pass complex data types(List, Set, and Map), custom data types to a future method. We always have to send primitive data types.