You need to sign in to do that
Don't have an account?
sfdck
Difference between synchronous and asynchronous in apex
Hi ,
I am confused between synchronous and asynchronous can any one explain me from the scratch what are they actually , and when we use the @future annotation . Please Help me !!!
Help is highly appreciated.
Thanks in Advance.
An aysch call is queued up in Salesforce and run on a separate thread of execution. At this point it becomes decoupled from the calling action. That also means the calling action won't block and wait for a response from the asycn call. Using the future annotation identifies methods that are executed asynchronously. They must also be static methods. There are some considerations to know when using aync methods, you can learn more here: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_future.htm
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
Asynchronous apex is excuted when resources are available. So any calling method which calls Asynchronous apex wont wait for outcome of Asynchronous call. Calling method will go on further execution in code. And Asynchronous execution happens in sperate thread and then it will return to main program.
Above said is at very basic and rough level description.
For detailed one, refer SFDC documentation.
https://developer.salesforce.com/page/Asynchronous_Processing_in_Force_com
Asynchronous processes are queued in salesforce and are executed as soon as resources are available. But there is no guarantee when this will be executed. Hence not suitable for processes if some time sensitive action is planned based on the outcome of this process
Asynchronous processing includes @future Apex, batch Apex or scheduled apex.
Asynchronous processes have higher governer limits compared to synchronous apex.
@future annotation is used to define a future method (a method that runs asynchronously). The method must be static and return type of the method should be void and take primitive data types or arrays of primitive data types as arguments.
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_future.htm
Asynchronous Apex -> Executes when the resources are available as part of mutli tenant architectue, when we call.