+ Start a Discussion
penchala rajupenchala raju 

what is synchronous & asynchronous operation in future method

pconpcon
All actions inside the future method are "synchronous."  The method is fired asynchronously from the rest of the code.  For example:


TRANSACTION 1
  • Trigger on Case that inserts CaseComment
  • Trigger on CaseComment that calls a @future method "UpdateCaseMilestones"
After transaction 1 completes, transaction 2 starts

TRANSACTION 2
  • UpdateCaseMilestones method start
  • Updates Case with data from CaseMilestone
All of the information in Transaction 1 and 2 are synchronous to their respective transactions.  However transaction 2 is asynchronous to transaction1.
rajesh gandirajesh gandi

Synchronous: everything is done in a single transaction

Asynchronous: everything is done in multiple transactions! 

One transaction is beneficial if you need to get certain information back from your method - for example, if you need to get an error/success message.  Also, since it's done on the same transaction, you get your results right away.

Multiple transactions are beneficial if you don't care if it works or not, you just want to save resources.

@Future Annotation:
Use the future annotation to identify methods that are executed asynchronously. When you specify future, the method executes when Salesforce has available resources.

@Future (callout = true)
Specify the method to make the callout to external systems. (e.g. To execute callout method via an Apex trigger)

Further details:
.
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_future.htm

U got answer please select best answer