Master Salesforce Developer Interview Questions | 2020
Salesforce Developer Interview Preparation 2020
NOTE: All the below questions are not belongs to any specific company or organisation. These are general questions asked in the interviews.
- You need to comment down your Answers in the comments section of this blog only.
- While commenting your answers mention the Question No. for example Question No. 1: Your AnswerXXXX.
- Once you are done with the Answer mention Your Name as Trailblazer Name: XXXX XXXX.
- You can answer single or multiple answers in the same fashion as mentioned above.
- Your Answer Pattern should start with a simplified version of definition (Not copy-pasted from somewhere) and as you know this SFDC Kid is known for simplifying the explanation, which a Small Kid can also understand.
- The best answer will be selected based on Simplified Version of concept to get featured.
- All the selected answers will be available immediately after the questions along with the trailblazer Name.
- Updating and selecting the answer will be in a weekly frequency. If you have better answer than the featured one post your counter Answer as Counter Question No.1 : Your AnswerXXX
Q.3 Explain Controller and Extension (difference, execution pattern, when to refer to what)?
---------------------------------
As the name suggest "GET" method fetch value of variables used in VF page from its controller or extension
and "SET" method sets the value of the variables in apex controller or extension
In short you can say that we use Get and Set methods to communicate between our VF page and Apex class i.e, for passing data
For ex:- If you want to display your name in VF page like this:
here {!myname} is your variable
now, Apex code to get and set this variable value will be like this:
public class GetSetController{
**Note:- always write getVariableName and setVariableName otherwise you will get error**
//declare a local variable to pass it to SET method to set the actual variable
public String myname;
//get method
//here return type will change accordingly
public String getmyname(){ return 'SFDC Kid' ;}
//set method
public void setmyname(String myname) (
this.myname = myname;
}
Now, whenever you will load your page You can see value "SFDC Kid". It will be default/static value
Now if you want dynamically get and set the variable values then you have to modify your code like this:
Apex Class :
public class GetSetController {
//This is another way to write getter and setter methods whenever you are dealing //with dynamic value scenario
public String myname{get; set;}
}
Here when you enter any value in the textbox it will be stored in {!myname} variable i.e., GET method and
when you hit enter button same time this value is set on the same variable and show on below line on the same page i.e., the SET method
TrailBlazer Name : - Akshata
---------------------------------
The test class coverage should be minimum of 75% to deploy it to production.
But note that it should cover all positive as well as negative test cases
Positive Case: You will give all necessary data in your test class and check whether you are getting output as expected in the assert statement.
For ex: If your functionality is saving record of Account. In the test class, you will give all necessary data to create an account and at last, in assert statement, you will check whether its working fine or not.
Negative Case: There is no negative test case as such because negative test cases are similar to the positive case only but from a different perspective. I used this term just to differentiate between 2 scenarios of writing
test cases
Here you will check what if user enter wrong/invalid data or did not enter any data and hit save button then in that case Account should not insert and you already have written logic to throw an error in your Apex class
Then in test class also you will not give required values while giving dummy data and check whether it's covering that line of code from your class
Create Common Test Utility Classes For Test Data Creation:
- Test Utility Class is nothing but creation of test data which is reusable
while writing test classes while inserting test data
- Its start with @isTest annotation and public always
- You can write different methods for each object test data creation. This
method are written in similar way as we write in apex class
There are few key points you have to remember while writing test class:
1.Best practice says write your test class name in this form : ApexClassName+Test
2.Start test class with @isTest annotation
3.To write test class methods you have 2 choice either you can simply write methods as you write in your apex class and will put @isTest annotation before it
or write as testmethod keyword before it
4.All methods must be static and void
5. Now if your class deals with functionality of multiple objects then you can write @testSetup method to give all required test data at start of test class only
for ex: - @testSetup
public static void insertTestData(){}
Use this test data in other test methods
Otherwise you can give test data inside each method also
6. System.debug statements are not counted in test class
7. Use Test.startTest and Test.stopTest while actual testing so that your testing will not face governor limit errors as it get refreshed always before your actual testing
8.You must write System.assert once testing is done to check whether your functionality is giving same output as you expected
Annotations Used in Test class and its significance
1.@isTest ==> Indicates it is test class so that it will not get counted in governor limit for apex class
2.@testSetup ==> Indicated test data setup method and provide required test data for other test methods
3.test.startTest => Indicates testing has been started so that governor limits will get refreshed
4.test.stopTest ==> Indicated testing is done.
5.Test.isRunningTest() ==> to ensure trigger will not fire if its value is true to avoid limit exception also in your callout code its indicates context while unit testing so that actual
callout will not happen and will return a predefined string that we have written
6.test.runAs ==> to test functionality in different user context
System.assert Methods
1.system.assert ==> here you will just check returned value or boolean value if apex method does not return anything
2.system.assertEquals ==> you will compare expected and actual values
3.system.assertNotEquals ==> here actual and expected values will be different in order to execute test case otherwise error will be thrown
Trailblazer Name - Akshata
ANS :
---------------------------------
When object has not been initiated or attribute of object has not been initiated and still you trying to access attribute of that object you will receive an error " System.NullPointerException: Attempt to de-reference a null object".
for example :
Account objAccount;
System.debug(objAccount.name); // this line you will get an error
Trailblazer Name : Satya Jarag
---------------------------------
ANS :
---------------------------------
When in a single transaction we are trying to perform insert/update/delete operation on set-up and non-setup objects then we receive MIX DML Error.
Setup objects can be classified as User,Profile etc and non-setup objects can be classified as Account,Contact and our custom objects are also counted against non-setup objects.
So if it is necessary to perform DML operation on both set-up and non-setup objects in a single transaction then we have to break the transaction and we can achieve that by implementing the asynchronous method i.e. future method.
Below code will be helpful :
#before implementing future
User usr = [SELECT ID,Email FROM USER WHERE Id = : UserInfo.getUserId()];
user.email = sfdckid@salesforce.com
update use;
Account acc = [Select Id,Name FROM Account LIMIT 1];
acc.name='salesforcekid';
update acc;
In above example when we will try to update User and Account we will get MIX DML Operation Error so in-order to avoid it we will be implementing future method 2 break transaction into 2 parts.
#after implementing future
Account acc = Account acc = [Select Id,Name FROM Account LIMIT 1];
acc.name='salesforcekid';
update acc;
calling another class in the same logic which will be implementing future method.
class ImplementFuture{
@future updateUser(){
User usr = [SELECT ID,Email FROM USER WHERE Id = : UserInfo.getUserId()];
user.email = sfdckid@salesforce.com
update use;
}
}
Trailblazer Name : Abhishek Singh
---------------------------------
If you like this SFDCkid learning platform please let me know in the Comment section...Also, Share with your salesforce folks wish you all
Happy Learning ☁️⚡️ (Learn. Help. Share.) 😊
Sosl to be used when we don't know where is data we need to search . Also when we need quick results (sosl is more efficient than soql). Soql help us query on related objects (parent and child) only. Sosl gives only 2000 records. Soql can give 50000 records. 100 Soql is allowed per transaction sosl only 20.also sosl can't be used in triggers
ReplyDeleteHi Ankit,
DeleteCould you please submit your answer in the format mentioned above in the post to consider your answer ?
Thanks in advance! 😊
⚡️HAPPY LEARNING ⚡️
I didn't got the 24th question (What is URL In Aura Component) and 35th question (what is inside batxh apex)
ReplyDeleteQuestion 11 : when object has not been initiated or attribute of object has not been initiated and still you trying to access attribute of that object you will receive an error " System.NullPointerException: Attempt to de-reference a null object".
ReplyDeletefor example :
Account objAccount;
System.debug(objAccount.name); // this line you will get an error
Trailblazer Name : Satya Jarag
Thanks for answering Satya 😊
DeleteCongratulations 🥳🎉☁️⚡ Your answer is now featured below the given Question.
⚡Happy Learning⚡
Q.28 What is Mix DML Exception (Reason, How to avoid it)?
ReplyDeleteAns ) When in a single transaction we are trying to perform insert/update/delete operation on set-up and non-setup objects then we receive MIX DML Error.
Setup objects can be classified as User,Profile etc and non-setup objects can be classified as Account,Contact and our custom objects are also counted against non-setup objects.
So if it is necessary to perform DML operation on both set-up and non-setup objects in a single transaction then we have to break the transaction and we can achieve that by implementing the asynchronous method i.e. future method.
Below code will be helpful :
#before implementing future
User usr = [SELECT ID,Email FROM USER WHERE Id = : UserInfo.getUserId()];
user.email = sfdckid@salesforce.com
update use;
Account acc = [Select Id,Name FROM Account LIMIT 1];
acc.name='salesforcekid';
update acc;
In above example when we will try to update User and Account we will get MIX DML Operation Error so in-order to avoid it we will be implementing future method 2 break transaction into 2 parts.
#after implementing future
Account acc = Account acc = [Select Id,Name FROM Account LIMIT 1];
acc.name='salesforcekid';
update acc;
calling another class in the same logic which will be implementing future method.
class ImplementFuture{
@future updateUser(){
User usr = [SELECT ID,Email FROM USER WHERE Id = : UserInfo.getUserId()];
user.email = sfdckid@salesforce.com
update use;
}
}
Trailblazer Name : Abhishek Singh
Well Done!! Abhishek 😊
DeleteCongratulations 🥳🎉☁️⚡ Your answer is now featured below the given Question.
⚡Happy Learning⚡
Question 7 : The code must have 75% code coverage in order to be deployed to Production. This code coverage is performed by the test classes. Test classes are the code snippets which test the functionality of other Apex class and Triggers without manual efforts.
ReplyDeleteThe test class are written under @isTest annotation. By using this annotation for test class we maintain code limit as it is not counted in it. Create Raw-Data At First: The Test Class In Apex Salesforce does not have access to any of the data which is stored in the related Salesforce org by default.
The best practice is to name your test class as your original Class or trigger Name + 'Test'. Methods of your test class have to be static, void and testMethod keyword has to be used.
Trailblazer Name : Lalit Kashyap
Question 36 : DX stands for developer experience and it is for salesforce continuous integration and release management and it is aimed at providing a more modern user experience for Salesforce developers.
ReplyDeleteDX promises a shift to modern life-cycle management tools for coding on the Force.com platform. Salesforce DX is designed to help Salesforce developers “build together and deliver continuously with modern deeloper experience.
With Salesforce DX, you can now benefit from modern collaboration technologies such as Git to version control everything across your team - your code, your org configuration, and your metadata. To make this possible, we're enabling you to export more of your metadata, define data import files, and easily specify the edition, features, and configuration options of your development, staging, and production environments.
Salesforce DX, introduces a new type of environment: Scratch orgs. Scratch orgs are source-driven and disposable deployments of Salesforce code which can be used to drive development, testing, and continuous integration. You can quickly spin up a dedicated scratch org to test your code and, once you've validated your changes, you can use your own continuous integration tools to immediately test and promote your code. As soon as your tests are passing, you can merge your branch, build packages, and deploy to a staging sandbox for final testing
Salesforce DX gives you an amazing developer experience out-of-the-box, while enabling you to bring the tools of your choice to meet the needs of your team . Built around a powerful command-line interface and open APIs, you have the flexibility to build with the tools you know and love. Whether you prefer to code in a text editor or prefer the modern convenience of an integrated development environment, we have you covered! Want to use Jenkins or Selenium? No problem!
Salesforce DX introduces a new way to organize your metadata and distribute your apps. With Managed Packages, enterprise customers and partners can adopt a source-driven, CLI-centric approach to automate and manage the end-to-end lifecycle and deliver apps in a modern and efficient manner. Managed packages take full advantage of Salesforce DX tools including Scratch Orgs, the Salesforce CLI, and VS Code to improve the experience of your development team while working with the Salesforce Platform.
Trailblazer Name : Lalit Kashyap
Hey Lalit!! This Answers seems to be copy pasted from https://developer.salesforce.com/platform/dx
DeleteHence it will not be consider for this quiz as mentioned in the Rules of answer selection.
I request you to please go through all the rules before commenting your answers 😊 Looking forward to genuine answer next time.
⚡️HAPPY LEARNING⚡️
Question 42 : Every record within Salesforce is assigned a record ID when created. This ID is unique throughout your Salesforce org, and is referenced frequently when performing operations using existing Salesforce data. The API (e.g. Data Loader) will accept 15 or 18 character IDs, but will return 18 character IDs by default.
ReplyDeleteThe two versions are used in different situations. 15 character ID is a case-sensitive version which is referenced in the Salesforce user interface. You can use this ID while performing data operations through the user interface. 18 character ID is the case-insensitive version which is referenced through the APIs(e. g. Data Loader ).
other than record Id Salesforce also allows you mark up to 3 fields as External IDs and these fields must be text, number or email field types. Values in these External ID field must also be unique and you can also determine whether or not value are case sensitive
Trailblazer Name : Lalit Kashyap
Question No. 4: ANSWER
ReplyDeleteAs name suggest "GET" method fetch value of variables used in VF page from its controller or extension
and "SET" method sets value of the variables in apex controller or extension
In short you can say that we use Get and Set methods to communicate between our VF page and Apex class i.e, for passing data
For ex:- If you want to display your name in VF page like this:
here {!myname} is your variable
now, Apex code to get and set this variable value will be like this:
public class GetSetController{
**Note :- always write getVariableName and setVariableName otherwise you will get error**
//declare a local variable to pass it to SET method to set actual variable
public String myname;
//get method
//here return type will change accordingly
public String getmyname(){ return 'SFDC Kid' ;}
//set method
public void setmyname(String myname) (
this.myname = myname;
}
Now whenever you will load your page You can see value "SFDC Kid". It will be default/static value
Now if you want dynamically get and set the variable values then you have to modify your code like this:
Name :
Apex Class :
public class GetSetController {
//This is another way to write getter and setter methods whenever you are dealing //with dynamic value scenario
public String myname{get; set;}
}
Here when you enter any value in the textbox it will be stored in {!myname} variable i.e.,GET method and
when you hit enter button same time this value is set on the same variable and show on below line on same page i.e.,SET method
TrailBlazer Name : - Akshata
Question 7
ReplyDeleteBasically we write test class to check whether our functionality will run in all types of scenarios as expected. In short our apex class should handle errors in proper way
The test class coverage should be minimum 75% to deploy it to production.
But note that it should cover all positive as well as Negative test cases
Positive Case : You will give all necessary data in your test class and check whether you are getting output as expected in assert statement.
For ex: If your functionality is saving record of Account. In test class you will give all necessary data to create account and at last in assert statement you will check whether its working fine or not.
Negative Case : There is no negative test case as such because negative test cases is similar to positive case only but from different perspective.I used this term just to differentiate between 2 scenarios of writing
test cases
Here you will check what if user enter wrong/invalid data or did not enter any data and hit save button then in that case Account should not insert and you already written logic to throw error in your Apex class
Then in test class also you will not give required values while giving dummy data and check whether its covering that line of code from your class
Create Common Test Utility Classes For Test Data Creation:
- Test Utility Class is nothing but creation of test data which is reusable
while writing test classes while inserting test data
- Its start with @isTest annotation and public always
- You can write different methods for each object test data creation. This
method are written in similar way as we write in apex class
There are few key points you have to remember while writing test class:
1.Best practice says write your test class name in this form : ApexClassName+Test
2.Start test class with @isTest annotation
3.To write test class methods you have 2 choice either you can simply write methods as you write in your apex class and will put @isTest annotation before it
or write as testmethod keyword before it
4.All methods must be static and void
5. Now if your class deals with functionality of multiple objects then you can write @testSetup method to give all required test data at start of test class only
for ex: - @testSetup
public static void insertTestData(){}
Use this test data in other test methods
Otherwise you can give test data inside each method also
6. System.debug statements are not counted in test class
7. Use Test.startTest and Test.stopTest while actual testing so that your testing will not face governor limit errors as it get refreshed always before your actual testing
8.You must write System.assert once testing is done to check whether your functionality is giving same output as you expected
Annotations Used in Test class and its significance
1.@isTest ==> Indicates it is test class so that it will not get counted in governor limit for apex class
2.@testSetup ==> Indicated test data setup method and provide required test data for other test methods
3.test.startTest => Indicates testing has been started so that governor limits will get refreshed
4.test.stopTest ==> Indicated testing is done.
5.Test.isRunningTest() ==> to ensure trigger will not fire if its value is true to avoid limit exception also in your callout code its indicates context while unit testing so that actual
callout will not happen and will return predefined string that we have written
6.test.runAs ==> to test functionality in different user context
System.assert Methods
1.system.assert ==> here you will just check returned value or boolean value if apex method does not return anything
2.system.assertEquals ==> you will compare expected and actual values
3.system.assertNotEquals ==> here actual and expected values will be different in order to execute test case otherwise error will be thrown
Trailblazer Name - Akshata
Well Done!! Akshata 😊
DeleteCongratulations 🥳🎉☁️⚡ Your answer is now featured below the given Question.
⚡Happy Learning⚡
Question 1 : Batch Apex is a global Apex class that implements Database.Batchable interface. Now, the order of execution of the methods implemented are as follows.
ReplyDelete1. start()
2. execute()
3. finish()
For Example :
global class BatchClass implements Database.Batchable {
global (Database.QueryLocator / Iterable) start(Database.BatchableContext bc) {
// Queries or gathers the records or objects to be passed to execute
}
global void execute(Database.BatchableContext bc, List records){
// process and perform operations to each batch of records
}
global void finish(Database.BatchableContext bc){
// execute any post operations or processing tasks
}
}
Trailblazer Name : Himanshu Baghmar
Hey Himanshu!!
DeleteCould you please add some more explanation as describe in the rules of posting the answer. for example you can explain how and when exactly the execution of each methods takes place etc.
I hope this will help to expand it.
⚡️HAPPY LEARNING⚡️
Question 1 : Batch Apex is a global Apex class that implements Database.Batchable interface. Now, the order of execution of the methods implemented are as follows.
Delete1. start() : This method will be the first method to be called in a Batch Job. The method gathers or collects the data on which the Batch job will be performed.
->We use the Database.QueryLocator object when we are using a simple query to fetch the records of the objects used in the batch job. The SOQL data governer limit is bypassed.
->We use the iterable object when we have complex scope for the Batch job. Database.QueryLocator gives the scope of records which the batch should process.
2. execute() : This method will be called after the completion of START method. This method is responsible for performing all the tasks required for Batch Job. The methods contains two parameters 'Database.BatchableContext' instance and the List of sObject. The List of sObject contains the list of records collected or gathered in START method.
3. finish() : This method will be called at the end. This method is used for doing some post operations or finishing activities like sending an email.
For Example :
global class BatchClass implements Database.Batchable {
global (Database.QueryLocator / Iterable) start(Database.BatchableContext bc) {
// Queries or gathers the records or objects to be passed to execute
}
global void execute(Database.BatchableContext bc, List records){
// process and perform operations to each batch of records
}
global void finish(Database.BatchableContext bc){
// execute any post operations or processing tasks
}
}
Trailblazer Name : Himanshu Baghmar
This is a great blog. I am pretty much impressed with your good work. You put really very helpful information. Keep it up
ReplyDeleteHR consultancy in velachery
HR consultancy in chennai
Hey There. I found your blog using msn. This is a very well written article. I’ll be sure to bookmark it and come back to read more of your useful info. Thanks for the post. I’ll definitely return. ecommerce development salt lake city
ReplyDelete