Category:

Salesforce

    Top 20 Salesforce Interview Question – Integration

    Top 20 Salesforce Interview Question – Integration

    This post has top 20 question related to Salesforce integration and asynchronous apex.  Asynchronous apex and integration are very  important for processing large data sets.

          1. Why we need integration in Salesforce?
            Ans.
            Integration comes in picture when some interaction is required from external system. Let us take example, we want to validate address of account record. This can be done using google address validation or smarty street API integration.
          2. What are types of integration patterns in salesforce?
            Ans.

            Pattern Description
            Remote Process Invocation—Request and Reply This pattern will come in picture when we call any external website and wait for its response.
            Example : For verifying address, call address validation API and based on response update flag in system.
            Remote Process Invocation—Fire and Forget This pattern will come in picture when we call any external website and don’t wait for its response.
            Example: For updating external system, send data using consuming API.
            Batch Data Synchronization Data is created or updated from external system or we send data to external system using batch.
            Example : Send batch update for transaction amount updation on daily basis.
            Remote Call-In Record is creating, updated, deleted or retrieved in our system using external system.
            Example : External system will update order detail in salesforce.
            UI Update Based on Data Changes Salesforce user interface changes based on udpation 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 do 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 process in a separate thread at later time in background. Mostly these is used where large volume of data processing is required or based on HTTP callout some update in record is required.
          4. What are types of Asynchronous Apex?
            Ans.
            Majorly this is 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 we used?
            Ans.

            Batch Apex:
            Batchable Apex are 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 job.
            Future Methods:
            Unlike Batchable methods, they were lighter on resources and perfect for doing that job that Batchable was doing before, but much more efficiently. Future methods used to isolate DML operations on different sObject types to prevent the mixed DML error. Mixed DML error is occurred in synchronous mode where in same transaction insert and update command fired.
            Queueable Apex:
            Ans. Queueable is hybrid between the limited future methods and the resource-hungry Batchable interface. Queueable is lighter than Batchable. It gives a Job ID and let us store complex data patterns.
          6. Why we can’t pass sObject in future method?
            Ans.
            Future method are executed in own time. sObject might change between the time it is called the method and the time it executes.
          7. What is future call limit?
            Ans.
            Maximum number of future method invocations per a 24-hour period is 250,000 or the number of user licenses in organization multiplied by 200, whichever is greater.
          8.  How many child job can be created in Queueable apex?
            Ans.
            Only 1 child job can be created for 1 parent job. There is no limit for depth of chaining job. For developer and trial maximum chaining depth is 5. It means total 4 chain job will be possible.
          9. To process 10000 record with HTTP Callout, what could be better approach in queueable apex?
            Ans.
            Create two queueable job in this scenario. One queueable job will get all records using SOQL and map. Pass map list to another job where 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 maximum limit for callout in any job?
            Ans.
            100 callouts can be done in one job. If it will exceed then max callout exceed exception will throw.
          11. Why we can’t call 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 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 error “Too many queueable jobs added to the queue”?
            Ans.
            There is limitation that multiple queueable job cannot created 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 edition it is maximum 5.
          14. Can I begin a batch job upon completion of another batch job?
            Ans.
            Yes, we can start a new batch when first batch is completing. This is done in finish method. Example: We want to send email to all customer which is 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 job with multiple records and for each record there is callout. Based on callout response we need to update record in system.Reason: Actually, webservice or http callouts and a DML won’t take place in the same transaction.
            Solution:
            1. We can use Queuable Apex with 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 “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 status of job which is created from Database.executeBatch?
            Ans.
            We can use AsyncApexJob for getting status of job.
            Example:

            SELECT Id, Status, ApexClassID, JobItemsProcessed, TotalJobItems, JobType, CompletedDate, ExtendedStatus FROM AsyncApexJob WHERE Id =: 'id' 
            
          18. How to get class name which has executed the job?
            Ans.
            AsyncApexJob object has this information. We can use 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 purgeOldAsyncJobs method. 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 job using System.abortJob. We have to get scheduled job using CronTrigger and then pass id to System.abortJob.

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

    Best of luck for interview. 

    January 17, 2020 8 comments
    3 Facebook Twitter Google + Pinterest