Close Menu
SalesforceCodex
    Facebook X (Twitter) Instagram
    Trending
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    • Top 10 PMD Issues Salesforce Developers Should Focus on in Apex
    • How to Use Graph API for Outlook-Salesforce Connection
    Facebook X (Twitter) Instagram
    SalesforceCodex
    Subscribe
    Thursday, May 29
    • Home
    • Architecture
    • Salesforce
      • News
      • Apex
      • Integration
      • Books Testimonial
    • Questions
    • Certification
      • How to Prepare for Salesforce Integration Architect Exam
      • Certification Coupons
    • Integration Posts
    • Downloads
    • About Us
      • Privacy Policy
    SalesforceCodex
    Home»Question»Salesforce Interview Question for Asynchronous Apex

    Salesforce Interview Question for Asynchronous Apex

    Dhanik Lal SahniBy Dhanik Lal SahniJune 30, 2022Updated:January 15, 20258 Comments8 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Salesforce Interview Question for Asynchronous Apex
    Share
    Facebook Twitter LinkedIn Pinterest Email

    The asynchronous process is a very important feature of Salesforce apex. Asynchronous process helps us in doing our long-running operations in the background so that it will not impact application performance. This post is related to Salesforce interview question for asynchronous apex. Let us see the all-important questions of Asynchronous Apex

    Q.1 What is Asynchronous Apex?

    While working on the Salesforce application, we store huge data in our org and it will keep growing year by year. If we have to run some job that will take some time then in the case of synchronous apex we will get the limit error, heap size error, or timeout error. To avoid such issues, we can do those long-running or time-consuming operations using Asynchronous apex which will run in a separate thread and will not impact the main thread. So Asynchronous Apex is used to run the process in a separate thread at a later time.

    Q. 2 Where we can use Asynchronous Apex?

    Asynchronous Apex can be used in long-running or time-consuming operations like

    • Sending Email to the user.
    • Creating complex reports using Apex code
    • Calling an external system for multiple records
    • Schedule a job for a specific time
    • Chaining apex code execution which might use API call
    • Sharing Re-calculation

    Q3. What are the benefits of Asynchronous processing?

    Asynchronous process runs when the system is available for operation. It is not blocking users from doing any work in the application. This will give the below benefit to application.

    • Increase User Efficiency
    • More Heap Size and Higher Governer limit
    • Better Scalability

    Q.4 What are the types of Asynchronous Apex?

    Currently, Salesforce supports four types of Asynchronous Apex.

    • Batch Apex
    • Future methods
    • Queueable Apex
    • Scheduled Apex

    Q.5 Within what timeframe will an asynchronous request be processed after being enqueued?

    Asynchronous processing has a lower priority than real-time interaction via the browser and API. So it will always run in the background when the resource is available to process asynchronous jobs. We can not determine when the job will run, it will be determined by the server. It can be immediate also.

    Q. 6 Can you make a web service callout from a trigger?

    We cannot call external web services synchronously from triggers, because calling a web service synchronously from triggers will hold up the database transaction until the callout is completed so we should use future methods to call external web services.

    Q. 7 Can a future method call another non-future method to process tasks like callouts, and have those methods return data to the future method for further processing?

    No, we can not call future methods from the future method.

    Q. 8 What are advantages of Batch Apex?

    • Every batch transaction starts with a new set of governor limits.
    • The system itself divides the number of batches for records
    • If one batch fails, the other batches will continue to be executed, and successful batches will still be committed to the database. Successful batches are not rolled back when one batch fails.

    Q. 9 Why use Batch Apex in Salesforce instead of the normal Apex?

    There are various reasons why Batch Apex is better than normal Apex.

    • SOQL queries: Normal Apex uses 100 records per cycle to execute SOQL queries. Whereas, Batch Apex does the same in 200 records per cycle.
    • Retrieval of SOQL queries: Normal Apex can retrieve 50,000 SOQL queries but, in Batch Apex, 50,000,000 SOQL queries can be retrieved.
    • Heap size: Normal Apex has a heap size of 6 MB; whereas, Batch Apex has a heap size of 12 MB.
    • Errors: When executing bulk records, Normal Apex classes are more vulnerable to encountering errors as compared to Batch Apex.

    Q. 10 What are some best practices when implementing batch apex?

    • Use normal Apex instead of Batch Apex when a small number of records need to run.
    • Use extreme care to invoke a batch job from a trigger. The trigger should not add more batch jobs than the limit
    • Methods declared as future aren’t allowed in classes that implement the Database.Batchable interface.
    • Methods declared as future can’t be called from a batch Apex class.
    • All methods in the class must be defined as global or public.
    • Minimize web service callout times.
    • Tune queries used in batch Apex code.
    • Minimize the number of asynchronous requests created to minimize the chance of delays.

    Q. 11 How many Schedulable Apex jobs can you have at one time? In other words, what is the maximum number of Apex classes that can be scheduled concurrently?

    100 Schedulable Apex jobs can be scheduled.

    Q. 12 Are synchronous web service callouts supported by Scheduled Apex?

    No. However, if Scheduled Apex calls a Batch Apex job which then makes a web service callout, the callout will be supported.

    Q. 13 What are best practices for future methods?

    • every future method invocation adds one request to the asynchronous queue, avoid design patterns that add large numbers of future requests over a short period of time.
    • Ensure that future methods execute as fast as possible.
    • If using Web service callouts, try to bundle all callouts together from the same future method, rather than using a separate future method for each callout.
    • Consider using Batch Apex instead of future methods to process a large number of records asynchronously. 

    Q. 14 Why sObject parameters not supported in future methods?

    The sObject might change between the time we call the method and the time it executes that’s why sObjects can’t be passed as arguments to future methods. In this case, the future method will get the old sObject values and might overwrite them.

    Q. 15 Can I chain a job that has implemented allowsCallouts from a Job that doesn’t have?

    Yes, callouts are also allowed in chained queueable jobs.

    Q. 16 Can I call Queueable from a batch?

    Yes, But it is limited to just one System.enqueueJob call per execute in the Database.Batchable class. Salesforce has imposed this limitation to prevent explosive execution.

    Q.17 In which scenario, we can’t call a future method from a batch Job?

    Calling a future method is not allowed in the Execute method, But a web service can be called. A web service can also call an @future method. So, we can define a web service having a future method invocation and call the web service from the execute method of Batch Job.

    Q.18 How Future method helps in avoiding Mixed DML errors?

    There are 2 kinds of sObjects in salesforce.

    1. Non-Setup: Account, opportunity, etc
    2. Setup: User, groups,Queue etc

    If we are performing DML on both kinds of sObject in a single transaction, the system doesn’t allow it and throws an exception called Mixed DML exception, stating that a transaction can not have a Mixture of DML operation(Setup and Non-Setup).

    To resolve this error, we can put DML operations of a particular kind in the Future scope. Since both the DML operations are isolated from each other, the transaction doesn’t fail.

    Q.19 Let’s say, we have run an apex batch to process 2000 records, and It is running with batch size 200. Now, while doing DML on 298th record, an error occurred, What will happen in that case?

    In batches, If the first transaction succeeds but the second fails, the database updates made in the first transaction are not rolled back.

    Since the batch size is 200, so the first batch will be processed completely and all data will be committed to DB. In seconds batch, if we are committing records using normal DML statements like insert, update then the whole batch will be rollbacked. So records 201 to 400 will not be processed.

    If we use the Database DML operations like Database.insert with AllOrNone as false, then partial commit can happen and only 298th record will not be processed in that batch, and a total of 97 records will be processed. Also, the other batch execution will not stop.

    Q.20 What is Database.QueryLocator & Iterable<sObject>?

    In Database.QueryLocator, we use a simple query (SELECT) to generate the scope of objects. The governor limit for the total number of records retrieved by SOQL queries is bypassed, i.e. it can return up to 50 million records.

    In Iterable<sObject>, we can create a custom scope for processing, which would be not possible to create using SOQL where clauses. the governor limit for the total number of records retrieved by SOQL queries is still enforced.

    Similar Posts for Salesforce Interview Question

    • Salesforce Interview Question for Integration
    • Salesforce Apex Interview Question
    • Queueable Vs Batch Apex In Salesforce
    • Avoid Batch Apex and Use Queueable Class
    • Difference Between With Security and Without Security in Apex
    • Mastering Technical Questions for Tech Lead/Salesforce Architect Interview-4
    • 20 Technical Questions to Test Your Skills in a Tech Lead/Salesforce Architect Interview-3
    • Interview Questions for Tech Lead /Salesforce Architect Interview – II
    • Top 20 Technical Questions for Tech Lead /Salesforce Architect Interview – I
    • Top 30 Scenario-Based Salesforce Developer Interview Questions
    • 20 Scenario-based Salesforce Developer Interview Questions
    • How to Choose Between SOQL and SOSL Queries

    References:

    Asynchronous Apex

    apex interview question Asynchronous apex Asynchronous Apex interview question batch apex batch job batch processing future method Queueable salesforce salesforce apex salesforce developer question Salesforce Interview Question salesforce interview question and answer sfdc developer question sfdc development interview question sfdc interview question
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleGeneric BreadCrumb Component for Portal
    Next Article Dynamic Code Execution using Callable Interface
    Dhanik Lal Sahni
    • Website
    • Facebook
    • X (Twitter)

    With over 18 years of experience in web-based application development, I specialize in Salesforce technology and its ecosystem. My journey has equipped me with expertise in a diverse range of technologies including .NET, .NET Core, MS Dynamics CRM, Azure, Oracle, and SQL Server. I am dedicated to staying at the forefront of technological advancements and continuously researching new developments in the Salesforce realm. My focus remains on leveraging technology to create innovative solutions that drive business success.

    Related Posts

    By Dhanik Lal Sahni4 Mins Read

    How to Build a Generic Modal Window in Lightning Web Component

    May 26, 2025
    By Dhanik Lal Sahni6 Mins Read

    Top 10 Salesforce Flow Features of Salesforce Summer ’25

    May 11, 2025
    By Dhanik Lal Sahni6 Mins Read

    Unlock the Power of Vibe Coding in Salesforce

    April 30, 2025
    View 8 Comments

    8 Comments

    1. Pingback: What is SOQL Injection? - SalesforceCodex

    2. Pingback: Class 5 EVS Quiz 1 for Chapter Super Senses - ProveGuru.com

    3. Sheetal on September 20, 2022 12:38 pm

      The interview questions & explanation is easy to understand . Thank you!!

      Reply
      • Dhanik Lal Sahni on September 23, 2022 9:56 am

        Welcome, Sheetal. I am happy, it is easy to understand.

        Thank You,
        Dhanik

        Reply
    4. Pingback: 20 Scenario-based Salesforce Developer Interview Questions

    5. Pingback: Top 30 Scenario-Based Salesforce Developer Interview Questions - Salesforce Codex

    6. Pingback: Salesforce Architect Interview Questions - Salesforce Codex

    7. Pingback: Questions for Tech Lead/Salesforce Architect Interview

    Leave A Reply Cancel Reply

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    • How to Choose Between SOQL and SOSL Queries July 31, 2024
    Archives
    Categories
    Tags
    apex (111) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code optimization (8) code review tools (3) custom metadata types (5) design principle (9) file upload (3) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (64) lightning-combobox (5) lightning-datatable (10) lightning component (30) Lightning web component (62) lwc (51) named credential (8) news (4) optimize apex code (4) Permission set (4) pmd (3) Queueable (9) rest api (23) S3 Server (4) salesforce (141) salesforce apex (46) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    • How to Choose Between SOQL and SOSL Queries July 31, 2024
    Archives
    Categories
    Tags
    apex (111) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code optimization (8) code review tools (3) custom metadata types (5) design principle (9) file upload (3) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (64) lightning-combobox (5) lightning-datatable (10) lightning component (30) Lightning web component (62) lwc (51) named credential (8) news (4) optimize apex code (4) Permission set (4) pmd (3) Queueable (9) rest api (23) S3 Server (4) salesforce (141) salesforce apex (46) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Facebook X (Twitter) Instagram Pinterest YouTube Tumblr LinkedIn Reddit Telegram
    © 2025 SalesforceCodex.com. Designed by Vagmine Cloud Solution.

    Type above and press Enter to search. Press Esc to cancel.

    Ad Blocker Enabled!
    Ad Blocker Enabled!
    Our website is made possible by displaying online advertisements to our visitors. Please support us by disabling your Ad Blocker.