Scenario Based Salesforce Interview Questions

Asking simple straightforward questions in Salesforce is history. Few years back Salesforce certified people were very less. Hence criteria was just to check whether that person know about Salesforce or not.

So questions used to be:
• What is Salesforce?
• What is account and contact?
• What is relationship between account contact?
• What is workflow?
• What is approval process?

If you notice above questions are crisp to the point. But now since in market there are many Salesforce certified people above style of interview doesn't work. One could easily memories these.

I too take interviews in my company and now style is different. Focus is more to ask scenario questions rather then what how etc.

Check Scenario Based Salesforce Interview Questions as one can have the theoretical knowledge. But the recruiters also checks for scenario based knowledge or Practical knowledge. Recruiters always ask tricky questions on the problems that one can face during implementation.

Only the person which has faced the problems while execution can only answer the questions.

In this blog, I have tried to cover Scenario Based Salesforce Interview Questions that are often asked from a Salesforce developer in an interview.

 Interview Series

Let start the interview series on Scenario Based Salesforce Questions (Between Interviewer & Interviewee).

 Interviewer: I have not given any CRUD permission in the profile ‘P1’ for an object O1, yet I’m able to create records for object ‘O1’. How could this be possible?

 Interviewee: Any permission with respect to creation /deletion/Updating/viewing of object is possible only through permission set or Profile.

Meaning If we are able to create records in a object then the Create Permission in either Profile or in Permission Set should be enables. If its not enabled in the Profile then it has be in the Permission set.

So check for the permission set.

 Interviewer: I am trying to implement Pagination. Initially i want to display 50 records and when user click on Next button, the records stating from 51 to 100 should get displayed. How do I accomplish this.


The interviewer may ask the same above scenario question in different ways.

For example : Describe OFFSET and give example and why we use?

 Interviewee: The key question here is how do we fetch next 50 records when user clicks on 'Next'?

One possible way to implement this is to have 'OFFSET' used in SOQL which fetches the records.

OFFSET is a clause which is used in SOQL query. When using offset only first batch of records are returned for a given query. If you want to retrieve next batch you will need to re-execute query with the highest OFFSET Value.

Example - A query like :

SELECT Name, AccountNumber, Type
FROM Account
WHERE Type = 'Customer - Direct'

 Understanding how the OFFSET technology works

The OFFSET function basically allows you to skip a number of rows when returning data. For example, you have a SOQL query that returns 100 rows and you want it see only 10, you would add "OFFSET 90" at the end of the SOQL query:


This feature is particularly handy in pagination (using the Limit function to break large amount of data into pages). Below is an example that uses both the LIMIT and OFFSET functions concurrently to return only 50 records to the user (as opposed to 100):


Then it will return record from 51 to 100.

One thing to keep in mind, according to Salesforce documentation, is that the OFFSET can handle a maximum of 2000 rows; otherwise it will result in a NUMBER_OUTSIDE_VALID_RANGE error.

 Interviewer: What are the type of exceptions that you got while coding in apex? How did u resolve those?

 Interviewee: In salesforce, there are some exceptions thrown when the governor limit is surpassed or something unexpected happens. Below are some of the exceptions listed and the reason of the throwing is also given: -

1. DmlException : Any problem with a DML statement, such as an insert statement missing a required field on a record.

The following is an example using the DmlException exception:

Account[] accts = new Account[]{new Account(billingcity = 'Bengaluru')};
try {
    insert accts;
} catch (System.DmlException e) {
    for (Integer i = 0; i < e.getNumDml(); i++) {
        // Process exception here

2. NullPointerException : Any problem with dereferencing null, such as in the following code:

String s;
s.toLowerCase(); // Since s is null, this call causes
                 // a NullPointerException

3. Too many DML rows: 10001 :This exception occurs when you try to process more than 10,000 records in a transaction whether it is insert , delete , update , upsert. As per Salesforce governor limit, you can only process upto 10,000 records in a transaction.


You can find other apex limits here. A key thing to note is that it is 10,000 records per transaction.

To avoid this exception, Batch apex can be used. Batch apex allows to process the records in multiple chunks(batches).

Example Scenario

If we have an org with 50,000 thousand account records and we use the code below, it will trigger the error: Too many DML rows 10001 as it will attempt to update 50,000 records in the update DML statement.

List<Account> accountList = new List<Account>();

//Retrieve all accounts in the org, lets assume there are 50,000 accounts in the org
for(Account account:[SELECT Id, Description from Account]){

   account.Description	='LearnFrenzy Description';

//The update will error as it is trying to update 50,000 accounts 
update accountList;

Solution: Batch Apex

Batch apex can run large jobs that can exceed the normal processing limits up to millions of records. When using batch apex the records can be processed asynchronously in batches to stay within the platform limits.

Batch Apex: UpdateAccountDescriptions.apxc

global class UpdateAccountDescriptions implements Database.Batchable<SObject>{

    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator('Select Id, Description FROM Account');

    global void execute(Database.BatchableContext BC, List<Account> accountsToUpdate){


            for(Account account:accountsToUpdate){
                account.Description ='Test Description From LearnFrenzy';

            update accountsToUpdate;

        }catch (Exception e){
           //Handle error

    global void finish(Database.BatchableContext BC){}

With the above batch class we can update the descriptions of 50,000 accounts without hitting the DML error. You can run a batch class from the developer console with anonymous apex.

Steps for run a batch class from the developer console with anonymous apex.

–> Click Debug in the developer console

–> Click Open Execute Anonymous window

–> Enter the below code to run the batch class, once the code is entered click execute

UpdateAccountDescriptions updateAccounts = new UpdateAccountDescriptions();

4. You cannot update Read Only Record :This type of exception occurs when you use a DML such as update in Before triggers. The DML for the current record is not at all permitted , as the record is not inserted yet and therefore it cannot be updated before insertion.

5. Mixed DML Exception :This type of exception occurs when you try to perform DML operation on setup objects(User, User Role), along with DML on other sObjects (non-setup Object such as Account, Contact) (or vice versa) in the same transaction.

To avoid this type of exception, one should do the operation separately in a different transaction. Or to use asynchronous apex such as future methods.

 Interviewer: Consider the scenario - I want to delete 20000 records and I don't want them to be recovered from recycle bin.


I want to do a mass delete on set of records and don't what them getting into recycle bin. What possible options do I have?

 Interviewee: Yes this is possible, Use Hard Delete Option.

Use "Hard Delete" option and the records are not recoverable via the Recycle Bin.

 Interviewer: Consider the scenario - I have a profile by name 'ProvideReadAccess' and two users U1 and U2 assigned to it. And I have object X.

My Question is I want to have 'ReadWrite' access for U1 and 'ReadOnly' access for U2 for the object X.
How do I do this?

 Interviewee: Read Access for both users is common hence in the Profile settings give 'Read' access for the object 'X’.

By doing this User U2 will be able to read all the records( One condition satisfied) but User U1 will also be able to only read the records(Second condition not satisfied).

So next what do we do is we create a permission set say 'GrantWriteAccess' and in this permission set we give the object 'X’ the Write access and assign the user U1 to this permission set.(2nd condition satisfied).

 Interviewer: Consider the scenario - I have Standard Controller and Controller Extension.

You can write all that logic in Controller Extension which can be written in Custom Controller. Also both Controller Extension and Custom controller execute in System Mode.

So Why do we need Custom Controller ?

 Interviewee: 1st point Controller Extension can’t exist on its own.

It has to be implemented on a Standard Controller or a Custom Controller.

So keeping the above point in mind, Let’s say certain methods needs to be executed in User Mode and certain in System Mode.

In this scenario it makes absolute sense to User Standard Controller with Custom Extension.

Where in using Standard Controller provides all preexisting features of platform. But note that When we use Standard Controller All the Sharing rules, permissions of a user are respected.

So if this what we wanted then we should go for an implementation of this sort. Other wise if we are building all features on own like Save Edit Update and delete then we should be using Custom Controller.


Understanding the Difference between Standard Controller, Custom Controller, and Extensions

Standard Controllers

Contains the same functionality and logic that are used for standard Salesforce pages. Can be used with standard objects and custom objects.

The standard controller is auto generated by SF for all objects.

<apex:page standardcontroller="Account">


In a standard controller, we will be getting access to 9 methods and we can use them to perform some standard out-of-the-box functionalities.

Custom Controllers

Custom controllers are written by you and do what your code tells them to do.

If I were to override the methods with my own custom functionality or implement a new method that not part of the 9 out of the methods then I need to create a Custom Controller.

<apex:page controller="CustomController">



An Apex Custom Controller and Apex Extension both are one and the same with the only difference that in an Extension we will be having a mandatory one argument constructor which is not the case with a Custom Controller.

public with sharing class CustomExtension{

	public void foobar(ApexPages.StandardController controller){

If I want to associate a Visualforce page with more than one Apex Class then we need to make use of an Extension.

The advantage of using an Extension is we can have up to 5 extensions by separating each of them with a comma.

If a method is implemented in both the Extensions, the extension that comes first that has the method implementation gets the priority and gets invoked.

<apex:page controller="CustomController" extensions="CustomExtensionOne,
                       CustomExtensionFive ">


 Interviewer: Consider the scenario - Let say I have a page which displays the set of records from Account object and I’m using a standard controller. Now I have two users belonging to same Profile. When they login and view this page, they get a message "Insufficient privileges".

What could be the reason for this? Or who would u arrive at a solution?


Notice below points:

Question speaks about standard Object and Standard Controller. Also remember permission to a object is given by Profile.

So we need to check if the user has permission to read data of this Object. Only if the permission is given to the user, he'll be able at access them else he will get an error message as "Insufficient privileges".

 Interviewer: Consider the scenario - If there is one object and we create two lookup field related to User object. And we have 3 users like A, B, C of same roles and same profile. If we have assigned two users in two lookup like A and B then only these two user can edit that object record, C user cannot be able to edit the record. How will i achieve this?


1. Make Sure Organization wide default for your custom object to Public Read Only.

2. Then create Trigger on your custom object to share record with your user using lookup field.


There is similar trigger which you can refer from here:

 Interviewer: Consider the scenario - I have two objects Obj1 and Obj2 which are not related to each other. Now I want to create a Master Detail Relationship(MDR) between these objects. How can I do this?


First choose which object has to be a Parent object(Master) and Child Object(Detail).
For our understanding lets say for now we decide Obj1 to be Master object and Obj2 to Detail object.

First lets under stand what’s a Master Detail relation ? Every child should have a parent. Which means every record in Obj2 should have a related parent record in Obj1. Also One child can have only one parent. But One parent can have multiple children.


Two scenarios are possible here.

Scenario 1: if there are pre existing records in the Obj2 then?

With the above understanding on Master Detail relation we have to be sure that every record in Obj2 has a related record in Obj1.

And in our scenario Obj1 and Obj2 are not related to each other. So first we have to create a basic Look up relation between these two objects so that we can establish a relation between these two objects.

So we follow below steps :

1st we create a Lookup field in the Child Object Obj2 pointing to Obj1 as parent.
2nd Update the Lookup field of all the records in Obj2 with a value from the Obj1 (Related field)
3rd Then we convert the Look up field to Master Detail relation.

Scenario2: If there are no pre existing records in the Obj2 then?

 Interviewer: What is the use of With Sharing and Without Sharing?

 Interviewee: With Sharing keyword is used with the class definition, which implies the sharing rules for that particular user will be considered. That means if the user doesn’t have access to a particular record, that record will not be processed.

public With Sharing class Sharingclass {

But when Without sharing is used, all records are processed for every user, no matter if the user has the access to the record or not.

public Without Sharing class nonSharing {


• If the class is not declared as With Sharing or Without Sharing then the class is by default taken as Without Sharing.

• Both inner class and outer classes can be declared as With Sharing.

• If inner class is declared as With Sharing and top-level class is declared as Without sharing, then the entire context will run in With Sharing context.

• Outer class is declared as With Sharing and inner class is declared as Without Sharing then inner class runs in Without Sharing context only. (Inner classes don't take the sharing properties from outer class).

 Interviewer: What will happen if a class is not declared with "With sharing" or "Without sharing" and it get called from another class which is declared with "With sharing"?

 Interviewee: If we do not declare class with "With sharing" or "Without sharing" the class will not take into account the sharing rules but if this class is called from another class which is declared with "With sharing" it will take into account the sharing rules.

 Interviewer: IF the class with "With sharing" is calling method of another class with "Without sharing" what will happen?

 Interviewee: IF the class with "With sharing" is calling method of another class with "Without sharing" than the method inside "Without sharing" class will execute without sharing rules.

 Interviewer:  IF the class with "Without sharing" is calling method of another class with "With sharing" what will happen?

 Interviewee: IF the class with "Without sharing" is calling method of another class with "With sharing" than the method inside "With sharing" class will execute with sharing rules.

 Interviewer: Can you edit apex classes or triggers in Production Environment?

 Interviewee: No, you can not edit apex classes or triggers directly in the Production Environment. The changes firstly needs to be made in a sandbox or Developer Edition org and then needs to be sent to production.

 Interviewer: Can we delete a user in Salesforce?

 Interviewee: No, we cannot delete a user. We can either deactivate a user or freeze it. There is no option to delete a user.

 Interviewer: Can you edit visualforce pages in Production Environment?

 Interviewee: Yes, you can directly edit and update the visualforce pages in production environment. Both options are there, either you can edit the vf page in the production itself or you can follow the traditional process of sending it from the sandbox or Developer Edition Org.

 Interviewer: How can we create a new profile same as the existing profile?

 Interviewee: In salesforce, there is an option of cloning the profile, by which you can create a new profile same as any other existing profile. To clone a profile,

Step -1 : Go to the profile that you want to clone.

Step -2 : Click on Clone.

Step -3 : Enter the new profile name that you want to create.

Step -4 : Click on Save.

Here for Example Profile Name is 'LearnFrenzy'

The permissions from the profile will be copied to the new profile and the users now can be assigned to the new profile.

 Interviewer: Consider the scenario - 

I have a User, Who will leave the organization tomorrow. He is basically a manager and there are 15 users below him.

Now when this user leaves the organization i would generally inactivate the User.

But now my concern is if I inactivate this user What happens to the Role hierarchy? the assignment rules, approval processes, the records created by him and records to which he is the default owner like leads and cases. 

And what would be best possible solution to keep this application intact and running and yet have this user de activated?

 Interviewee:  To prevent users from logging into your organization while you perform the steps to deactivate them, you can freeze user accounts. (Spring Summer 14)

So in this way until you find ways to remove this User from Role hierarchy/assignment rules/update the Owner of the records created by him/from any place where this user is used, we can make use of FREEZE button on the user record.


1. When we click on FREEZE button, the user will not be able to login to the application any more.

2. Freezing user accounts doesn't frees the user licenses available for use in your organization. We have to deactivate the user to free the license.

 Interviewer: What is having clause? Give the example.

 Interviewee: HAVING is a clause that can be used in a SOQL query to filter results that aggregate functions return. You can use HAVING clause with GROUP By clause to filter the results returned by aggregate function, such as SUM(). HAVING clause similar to WHERE clause.

The difference is that you can include in aggregate functions in a HAVING Clause , but not in WHERE Clause.

For Example

SELECT Id, Name FROM Lead;

It will return Lead record with Id and Name.


Then it will through error like Field must be grouped or aggregated: Id

SELECT Id, Count(Name) FROM Lead GROUP BY Name;

Then it will also through error , you cannot use same field name used in count

i.e.-- select id, count(name) from Lead GROUP BY name ^ ERROR at Row:1:Column:18 Grouped field should not be aggregated: Name

SELECT LeadSource, count(Name) 
FROM Lead 
GROUP BY LeadSource;

Now it will return record With LeadSource and count total name field correspond to particular LeadSource.

SELECT LeadSource, count(Name) 
FROM Lead 
GROUP BY LeadSource 
HAVING count(Name) > 6;

It will filter above group by query and return records which count is greater than 6.

 Interviewer: How to get the current user name and current user profile name in aura component without using apex?

 Interviewee: We can make use of Lightning Data service to access any of the user fields on the Lightning component without need to use apex controller.


    <aura:attribute name="currentUser" type="User"/>
    <force:recordData aura:id="recordLoader" 

Current User : {!v.currentUser.Name}

Current Profile : {!v.currentUser.Profile.Name}


       <c:UserProfile />

 Interviewer: Explain data binding in aura?

 Interviewee: Data binding is two way in aura framework i.e. parent to child component and child to parent component. Consider the below examples:

Parent Component: parentComponent.cmp

<aura:component >
    <aura:attribute name="parentVar" type="Integer" default="1"/>
    <c:childComponent childVar="{!v.parentVar}"/>
    parentVar: {!v.parentVar}

Child Component: childComponent.cmp

<aura:component >
    <aura:attribute name="childVar" type="Integer"/>
    <lightning:button label="change value" variant="brand" onclick="{!c.handleClick}"/>
    childVar: {!v.childVar}


    handleClick : function(component, event, helper) {
        var childVar = component.get("v.childVar");
        component.set("v.childVar", childVar+1);

       <c:parentComponent />

So in this example, the parent component attribute value parentVar is passed to child component attribute childVar. So initially, both the values are 1.

Once you click the button, you will see the childVar as well as parentVar is changed to 2. This is because any change made to childVar is reflected back to parentVar. We can think of it like call by reference.

Share This Post:

About The Author

Hey, my name is Saurabh Samir and I am Salesforce Developer. I have been helping to elevate your Salesforce Knowledge. Do comment below if you have any questions or feedback's.