Synchronous Apex:
Synchronous execution takes place as a single transaction and it does not wait for available resources and in Apex code is executed in one single go.
Example:
Trigger
Controller Extension
Custom Controller
Asynchronous Apex:
Asynchronous apex is executed when resources are available. So any calling method which calls Asynchronous apex won't wait for the outcome of Asynchronous call.
{
@future
public static void myFutureMethod()
{
// Perform some operations
}
}
global class FutureMethodRecordProcessing
{
@future
public static void processRecords(List<ID> recordIds)
{
// Get those records based on the IDs
List<Account> accts = [SELECT Name FROM Account WHERE Id IN :recordIds];
// Process records
}
}
global Database.QueryLocator start(Database.BatchableContext BC) { String query = 'SELECT Id,Name FROM Account'; return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List<Account> scope) { for(Account a : scope) { a.Name = a.Name + 'Account'; } update scope; } global void finish(Database.BatchableContext BC) { } }
No comments:
Post a Comment