Future Methods – @future in salesforce Apex

A future method runs asynchronously in background. You can use future method if you have long-running operations(callouts to external Web services or any operation that runs in its own thread and time. Also you can used for isolated DML operations. Each future method is queued and executes when system resources become available. Your program doesn’t have to wait for the completion of a future methods call.

Rules:
Methods with the future annotation must be static methods
Only return a void type
Cannot take sObjects or objects as arguments

If you want to pass sObjects that already exist in the database, pass the sObject ID or IDs and use the ID to perform a query in DB inside the future methods.


global class FutureExample
{
@future
public static void futureMethodExample()
{
// some operations
}
}

Share your love:

Leave a Reply

Your email address will not be published. Required fields are marked *