Future Methods #inSalesforce
This runs in the background, asynchronously. You can call a future method for executing long-running operations, such as callouts to external Web services or any operation you’d like to run in its own thread, on its own time.
Example:
Public class activateAccount{
@future
Public Static void updateAccount(List<Id> accountIds, Boolean active, String descptn){
List<Account> accounts = [Select id,Active__c,Description from Account where Id IN :accountIds];
for(Account a: accounts){
a.Active__c= true;
a.sampleDescription__c = descptn;
}
update accounts;
system.debug('!!!done!!!');
}
}
@future
Public Static void updateAccount(List<Id> accountIds, Boolean active, String descptn){
List<Account> accounts = [Select id,Active__c,Description from Account where Id IN :accountIds];
for(Account a: accounts){
a.Active__c= true;
a.sampleDescription__c = descptn;
}
update accounts;
system.debug('!!!done!!!');
}
}
In the anonymous window, try
List<Account> accounts = [Select id, Active__c, sampleDescription__c from Account];
List<Id> accountIds = new List<Id>();
for(Account a : accounts){
accountIds.add(a.Id);
}
activateAccount.updateAccount(accountIds,true,'activatedAccount');
List<Account> accounts = [Select id, Active__c, sampleDescription__c from Account];
List<Id> accountIds = new List<Id>();
for(Account a : accounts){
accountIds.add(a.Id);
}
activateAccount.updateAccount(accountIds,true,'activatedAccount');
Reference: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_invoking_future_methods.htm
Comments
Post a Comment