Home Question Top 20 Salesforce Developer Interview Questions

Top 20 Salesforce Developer Interview Questions

by Dhanik Lal Sahni

Top 20 Salesforce Developer Interview Questions

This post has the top 20 questions related to Salesforce integration and asynchronous apex.  Asynchronous apex and integration are very important for processing large data sets. Salesforce Developer Interview Questions

1. Why do we need integration in Salesforce?
Ans.
Integration comes into the picture when some interaction is required from an external system. Let us take an example, we want to validate the address of the account record. This can be done using Google address validation or smarty street API integration.

2. What are the types of integration patterns in salesforce?
Ans.

Pattern Description
Remote Process Invocation—Request and Reply This pattern will come into the picture when we call any external website and wait for its response.
Example: For verifying address, call address validation API and based on the response update flag in the system.
Remote Process Invocation—Fire and Forget This pattern will come into the picture when we call any external website and don’t wait for its response.
Example: For updating the external system, send data using consuming API.
Batch Data Synchronization Data is created or updated from an external system or we send data to an external system using batch.
Example: Send batch update for transaction amount updation on a daily basis.
Remote Call-In Record is created, updated, deleted, or retrieved in our system using an external system.
Example: External system will update order detail in salesforce.
UI Update Based on Data Changes Salesforce user interface changes based on updation in record data
Example: A customer service rep is on the phone with a customer working on a case record. The customer makes a payment, and the customer service rep does a real-time update in Salesforce from the payment processing application, indicating that the customer has successfully paid the order’s outstanding amount.
Data Virtualization Salesforce accesses external data in real-time. This removes the need to persist data in Salesforce and then reconcile the data between Salesforce and the external system.
Example:
Orders are managed by an external (remote) system. Sales reps want to view and update real-time order information in Salesforce without having to learn or use the external system.

3. What is Asynchronous Apex?
Ans. 
Asynchronous Apex is used to run processes in a separate thread at a later time in the background. Mostly these are used where a large volume of data processing is required or based on HTTP callout some update in the record is required.

4. What are types of Asynchronous Apex?
Ans.
Majorly there are four types which are as follows.
1. Queueable Apex
2. Scheduled Apex
3. Batch Apex
4. Future Methods

5. In which scenario Batch Apex, Queueable Apex, and future method should use?
Ans.

Batch Apex:
Batchable Apex is designed to allow for heavy asynchronous processing. It required a long time to process and was often used only to handle callouts or things that were slightly longer than a normal transaction could handle. Basically, it is used for large data volumes with long-running jobs.
Future Methods:
Unlike Batchable methods, they were lighter on resources and perfect for doing the job that Batchable were doing before, but much more efficiently. Future methods are used to isolate DML operations on different sObject types to prevent mixed DML errors. A mixed DML error occurs in a synchronous mode where in the same transaction insert and update commands are fired.
Queueable Apex:
Ans. Queueable is a hybrid between the limited future methods and the resource-hungry Batchable interface. Queueable is lighter than Batchable. It gives a Job ID and lets us store complex data patterns.

6. Why we can’t pass sObject in future methods?
Ans.
Future methods are executed in their own time. sObject might change between the time it is called the method and the time it executes.

7. What is the future call limit?
Ans. The maximum
number of future method invocations per a 24-hour period is 250,000 or the number of user licenses in the organization multiplied by 200, whichever is greater.

8. How many child jobs can be created in Queueable Apex?
Ans.
Only 1 child job can be created for 1 parent job. There is no limit to the depth of the chaining job. For developer and trial, the maximum chaining depth is 5. It means a total of 4 chain jobs will be possible.

9. To process 10000 records with HTTP Callout, what could be a better approach in queueable apex?
Ans.
Create two queueable jobs in this scenario. One queueable job will get all records using SOQL and map. Pass the map list to another job where the chaining job will be created for all records.
Example:
Child Job Class:

public class LetterChildJob implements Queueable, Database.AllowsCallouts{
    Map<Id,Letter__c> lettersToProcessed;
    public LetterChildJob (Map<Id, Letter__c> letters)
    {
        lettersToProcessed=letters;
    }
    public void execute(QueueableContext context) {
        integer counter=0;
        boolean createNewQue=false;
        try
        {
            for(ID index:lettersToProcessed.keySet())
            {
                // do the process
                // remove object from lettersToProcessed once process completed by HttpCallout
                counter=counter+1;
                if(counter>98)
                {
                    createNewQue=true;
                    break;
                }
            }
            if(createNewQue)
            {
                LetterChildJob esync = new LetterChildJob (lettersToProcessed);
        		System.enqueueJob(esync);
            }
        }
    	catch(Exception ex)
        {
            //Exception logic
        }
    }
}

Parent Job Class:

public class LetterParentJob implements Queueable, Database.AllowsCallouts{
    public void execute(QueueableContext context) {
        Map<Id,Letter__c> letters=new Map<id, Letter__c >([Select id,LETTER_TYPE_ID__c ,Name from Letter__c where Letter_sent__c==false]);
        LetterChildJob esync = new LetterChildJob (letters);
        System.enqueueJob(esync);
    }
}

10. What is the maximum limit for callout in any job?
Ans.
100 callouts can be done in one job. If it will exceed then the max callout exceeds exception will throw.

11. Why we can’t call a future method from another future method?
Ans.
If an @future method could be called from another @future method, one could have a chain of indeterminate length or even create a loop that would extend the execution of a transaction indefinitely through a very complex logic of additional execution contexts. Tracing the transaction to completion could become very complex.

12. How to avoid the error “Too many queueable jobs added to the queue”?
Ans.
There is a limitation that multiple queueable jobs cannot create by batch or another queueable job. To avoid that situation, we can do chaining of queueable jobs.

13. Is there a way to chain jobs indefinitely?
Ans.
Ideally, there is no limit for chaining of jobs but for test and developer editions it is a maximum of 5.

14. Can I begin a batch job upon completion of another batch job?
Ans.
Yes, we can start a new batch when the first batch is completed. This is done in the finish method. Example: We want to send emails to all customers which are processed using batch.

15. How to avoid error “System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out”?
Ans.
This error normally comes when we are running a job with multiple records and for each record, there is a callout. Based on the callout response we need to update the record in the system.Reason: Actually, web service or HTTP callouts and a DML won’t take place in the same transaction.
Solution:
1. We can use Queuable Apex with a callout to handle this error.
2. We can divide DML and callout in separate transactions.

16. Is it possible to get the ApexJobId within the Future method apex code or from the method its invoked from?
Ans.
No, Future is designed in response to Batchable’s excessive resource usage and cumbersome interface. It is work as a “fire and forget” type mechanism. It means that you can’t link any given future call to a Job ID reliably in Apex Code.

17. How to find the status of a job that is created from Database.executeBatch?
Ans.
We can use AsyncApexJob for getting the status of the job.
Example:

SELECT Id, Status, ApexClassID, JobItemsProcessed, TotalJobItems, JobType, CompletedDate, ExtendedStatus FROM AsyncApexJob WHERE Id =: 'id' 

18. How to get the class name that has executed the job?
Ans. The asyncApexJob
object has this information. We can use the below query for this.

Select  Status, ApexClassId, ApexClass.Name  From AsyncApexJob

19. How to delete old scheduled jobs?
Ans.
We have to purge old job records using the purgeOldAsyncJobs method. The code will be like below

global void finish(Database.BatchableContext BC)
{
  System.purgeOldAsyncJobs(Date.today());
}

20. How to delete future scheduled jobs?
Ans.
We should delete future jobs using System.abortJob. We have to get a scheduled job using CronTrigger and then pass it to System.abortJob.

for(CronTrigger ct:[SELECT Id FROM CronTrigger]) {
  System.abortJOb(ct.Id);
}

Other Interview Question Posts

Salesforce Interview Question for Asynchronous Apex

Salesforce Integration Interview Questions

Difference between Salesforce WSDL Files

Salesforce Apex Interview Question

Salesforce Security Interview Question

Difference Between Workflow and Process Builder In Salesforce Development

This post has the top 20 questions related to Salesforce integration and asynchronous apex.  Asynchronous apex and integration are very important for processing large data sets. Salesforce Developer Interview Questions

1. Why do we need integration in Salesforce?
Ans.
Integration comes into the picture when some interaction is required from an external system. Let us take an example, we want to validate the address of the account record. This can be done using Google address validation or smarty street API integration.

2. What are the types of integration patterns in salesforce?
Ans.

Pattern Description
Remote Process Invocation—Request and Reply This pattern will come into the picture when we call any external website and wait for its response.
Example: For verifying address, call address validation API and based on the response update flag in the system.
Remote Process Invocation—Fire and Forget This pattern will come into the picture when we call any external website and don’t wait for its response.
Example: For updating the external system, send data using consuming API.
Batch Data Synchronization Data is created or updated from an external system or we send data to an external system using batch.
Example: Send batch update for transaction amount updation on a daily basis.
Remote Call-In Record is created, updated, deleted, or retrieved in our system using an external system.
Example: External system will update order detail in salesforce.
UI Update Based on Data Changes Salesforce user interface changes based on updation in record data
Example: A customer service rep is on the phone with a customer working on a case record. The customer makes a payment, and the customer service rep does a real-time update in Salesforce from the payment processing application, indicating that the customer has successfully paid the order’s outstanding amount.
Data Virtualization Salesforce accesses external data in real-time. This removes the need to persist data in Salesforce and then reconcile the data between Salesforce and the external system.
Example:
Orders are managed by an external (remote) system. Sales reps want to view and update real-time order information in Salesforce without having to learn or use the external system.

3. What is Asynchronous Apex?
Ans. 
Asynchronous Apex is used to run processes in a separate thread at a later time in the background. Mostly these are used where a large volume of data processing is required or based on HTTP callout some update in the record is required.

4. What are types of Asynchronous Apex?
Ans.
Majorly there are four types which are as follows.
1. Queueable Apex
2. Scheduled Apex
3. Batch Apex
4. Future Methods

5. In which scenario Batch Apex, Queueable Apex, and future method should use?
Ans.

Batch Apex:
Batchable Apex is designed to allow for heavy asynchronous processing. It required a long time to process and was often used only to handle callouts or things that were slightly longer than a normal transaction could handle. Basically, it is used for large data volumes with long-running jobs.
Future Methods:
Unlike Batchable methods, they were lighter on resources and perfect for doing the job that Batchable were doing before, but much more efficiently. Future methods are used to isolate DML operations on different sObject types to prevent mixed DML errors. A mixed DML error occurs in a synchronous mode where in the same transaction insert and update commands are fired.
Queueable Apex:
Ans. Queueable is a hybrid between the limited future methods and the resource-hungry Batchable interface. Queueable is lighter than Batchable. It gives a Job ID and lets us store complex data patterns.

6. Why we can’t pass sObject in future methods?
Ans.
Future methods are executed in their own time. sObject might change between the time it is called the method and the time it executes.

7. What is the future call limit?
Ans. The maximum
number of future method invocations per a 24-hour period is 250,000 or the number of user licenses in the organization multiplied by 200, whichever is greater.

8. How many child jobs can be created in Queueable Apex?
Ans.
Only 1 child job can be created for 1 parent job. There is no limit to the depth of the chaining job. For developer and trial, the maximum chaining depth is 5. It means a total of 4 chain jobs will be possible.

9. To process 10000 records with HTTP Callout, what could be a better approach in queueable apex?
Ans.
Create two queueable jobs in this scenario. One queueable job will get all records using SOQL and map. Pass the map list to another job where the chaining job will be created for all records.
Example:
Child Job Class:

public class LetterChildJob implements Queueable, Database.AllowsCallouts{
    Map<Id,Letter__c> lettersToProcessed;
    public LetterChildJob (Map<Id, Letter__c> letters)
    {
        lettersToProcessed=letters;
    }
    public void execute(QueueableContext context) {
        integer counter=0;
        boolean createNewQue=false;
        try
        {
            for(ID index:lettersToProcessed.keySet())
            {
                // do the process
                // remove object from lettersToProcessed once process completed by HttpCallout
                counter=counter+1;
                if(counter>98)
                {
                    createNewQue=true;
                    break;
                }
            }
            if(createNewQue)
            {
                LetterChildJob esync = new LetterChildJob (lettersToProcessed);
        		System.enqueueJob(esync);
            }
        }
    	catch(Exception ex)
        {
            //Exception logic
        }
    }
}

Parent Job Class:

public class LetterParentJob implements Queueable, Database.AllowsCallouts{
    public void execute(QueueableContext context) {
        Map<Id,Letter__c> letters=new Map<id, Letter__c >([Select id,LETTER_TYPE_ID__c ,Name from Letter__c where Letter_sent__c==false]);
        LetterChildJob esync = new LetterChildJob (letters);
        System.enqueueJob(esync);
    }
}

10. What is the maximum limit for callout in any job?
Ans.
100 callouts can be done in one job. If it will exceed then the max callout exceeds exception will throw.

11. Why we can’t call a future method from another future method?
Ans.
If an @future method could be called from another @future method, one could have a chain of indeterminate length or even create a loop that would extend the execution of a transaction indefinitely through a very complex logic of additional execution contexts. Tracing the transaction to completion could become very complex.

12. How to avoid the error “Too many queueable jobs added to the queue”?
Ans.
There is a limitation that multiple queueable jobs cannot create by batch or another queueable job. To avoid that situation, we can do chaining of queueable jobs.

13. Is there a way to chain jobs indefinitely?
Ans.
Ideally, there is no limit for chaining of jobs but for test and developer editions it is a maximum of 5.

14. Can I begin a batch job upon completion of another batch job?
Ans.
Yes, we can start a new batch when the first batch is completed. This is done in the finish method. Example: We want to send emails to all customers which are processed using batch.

15. How to avoid error “System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out”?
Ans.
This error normally comes when we are running a job with multiple records and for each record, there is a callout. Based on the callout response we need to update the record in the system.Reason: Actually, web service or HTTP callouts and a DML won’t take place in the same transaction.
Solution:
1. We can use Queuable Apex with a callout to handle this error.
2. We can divide DML and callout in separate transactions.

16. Is it possible to get the ApexJobId within the Future method apex code or from the method its invoked from?
Ans.
No, Future is designed in response to Batchable’s excessive resource usage and cumbersome interface. It is work as a “fire and forget” type mechanism. It means that you can’t link any given future call to a Job ID reliably in Apex Code.

17. How to find the status of a job that is created from Database.executeBatch?
Ans.
We can use AsyncApexJob for getting the status of the job.
Example:

SELECT Id, Status, ApexClassID, JobItemsProcessed, TotalJobItems, JobType, CompletedDate, ExtendedStatus FROM AsyncApexJob WHERE Id =: 'id' 

18. How to get the class name that has executed the job?
Ans. The asyncApexJob
object has this information. We can use the below query for this.

Select  Status, ApexClassId, ApexClass.Name  From AsyncApexJob

19. How to delete old scheduled jobs?
Ans.
We have to purge old job records using the purgeOldAsyncJobs method. The code will be like below

global void finish(Database.BatchableContext BC)
{
  System.purgeOldAsyncJobs(Date.today());
}

20. How to delete future scheduled jobs?
Ans.
We should delete future jobs using System.abortJob. We have to get a scheduled job using CronTrigger and then pass it to System.abortJob.

for(CronTrigger ct:[SELECT Id FROM CronTrigger]) {
  System.abortJOb(ct.Id);
}

Other Interview Question Posts

Salesforce Interview Question for Asynchronous Apex

Salesforce Integration Interview Questions

Difference between Salesforce WSDL Files

Salesforce Apex Interview Question

Salesforce Security Interview Question

Difference Between Workflow and Process Builder In Salesforce Development

What is Monolithic Architecture?

What is Microservice Architecture?

You may also like

6 comments

sayant January 17, 2020 - 5:16 pm

An excellent material

Reply
Dhanik Lal Sahni January 17, 2020 - 7:38 pm

Thank You sayant.

Reply
Kishan January 17, 2020 - 6:22 pm

Thank You for sharing this nice blog

Reply
Dhanik Lal Sahni January 17, 2020 - 7:38 pm

Thank You kishan.

Reply
Dhanik Lal Sahni January 17, 2020 - 7:38 pm

Thank You Abhishek.

Reply
Dhanik Lal Sahni January 19, 2020 - 10:56 pm

Thank You Abhimanyu.

Reply

Leave a Comment