Summary
As we have seen in this chapter, future methods are a versatile and easy-to-work-with asynchronous processing option within Apex. They allow us to define discrete bundles of code that can be used to make long-running callouts or to avoid mixed DML errors when working with setup objects.
We have also seen some different methods of interacting with future methods to persist state and errors between transaction contexts, and finally, we have seen how our future methods can be tested.
The reason we focused on future methods first in this section is that they are the simplest to invoke (just require a static
method call) and therefore are easier to test. They also have limited out-of-the-box support for state transmission, which has to be worked through the use of an object that persists across the transaction context. For these reasons, it is recommended that you consider whether other platform options such as queueable Apex may better serve your needs.
In the next chapter...