Activity Forums Salesforce® Discussions Difference between synchronous and asynchronous in apex

  • shariq

    Member
    July 12, 2017 at 12:19 pm

    Synchronous Apex :-

    Synchronous term means existing or occurring at the same time. Synchronous Apex means entire Apex code is executed in one single go.

    Asynchronous Apex :-

    Asynchronous term means not existing or occurring at the same time. Asynchronous apex is executed 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 separate thread and then it will return to main program.

  • Radhakrishna

    Member
    July 13, 2017 at 4:38 am

    Hello Shubham,

    An async 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 async methods.

     

    you can learn more here: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_future.htm

  • Radhakrishna

    Member
    July 13, 2017 at 4:40 am
  • Parul

    Member
    September 14, 2018 at 1:17 pm

    Synchronous:

    In a Synchronous call, the thread will wait until it completes its tasks before proceeding to next. In a Synchronous call, the code runs in single thread.

    Example:

    Trigger
    Controller Extension
    Custom Controller

    Asynchronous:

    In a Asynchronous call, the thread will not wait until it completes its tasks before proceeding to next. Instead it proceeds to next leaving it run in separate thread. In a Asynchronous call, the code runs in multiple threads which helps to do many tasks as background jobs.

    Example:

    Batch
    @future Annotation

     

    Thanks

  • LOCHAN

    Member
    April 2, 2023 at 8:07 am

    Perfect ans

  • Shuvam

    Member
    May 15, 2023 at 4:07 pm

    Hi Everyone,
    So basically in Salesforce, Apex can be executed in two ways: synchronously and asynchronously. Here's a simple breakdown:
    Synchronous: This is like a two-way conversation. You ask a question, you get an answer right then. In synchronous processing, the code runs in a single thread, in the same sequence it's written, and the user waits for the request to complete before they can continue with their work. It's immediate, but it can also cause the user to wait if the process is long or complex.
    Asynchronous: This one's more like sending a letter. You send it off and go about your day, knowing you'll get a response later. Asynchronous processing in Apex allows you to run processes in the background while users continue with their work. This can be particularly useful for complex, time-consuming processes that you don't want to make the user wait for. Apex provides @future methods, Queueable Apex, Batch Apex for this kind of processing.
    Hope this helps! 🙂

  • Eden

    Member
    May 16, 2023 at 3:36 am

    In Salesforce Marketing Cloud training, synchronous calls and asynchronous calls refer to two different ways of executing code.
    Synchronous calls block further execution until the called code has finished executing and returned a response. This means that the calling code waits for the response before continuing. Synchronous calls are typically used for short and quick operations where the response time is critical.
    On the other hand, asynchronous calls do not block further execution and allow the calling code to continue executing while the called code is still processing in the background. This means that the calling code does not wait for the response and can perform other tasks. Asynchronous calls are typically used for longer and more complex operations where the response time is not critical.
    In Salesforce Marketing Cloud training, understanding the difference between synchronous and asynchronous calls is important for designing efficient and scalable code that can handle different types of operations.

    • This reply was modified 1 year, 5 months ago by  Eden.
    • This reply was modified 1 year, 5 months ago by  Eden.

Log In to reply.

Popular Salesforce Blogs