Top Salesforce Developer Interview Questions and Answers
Q. What is Apex?
- Apex is a strongly typed, object-oriented programming language that allows developers to extend the Salesforce platform by writing their own business logic into the platform. Apex looks similar to Java and can be launched through a variety of user-initiated events such as record updates, button clicks, triggers on objects, or external web service requests.
Q. What is an Apex Transaction?
- An Apex transaction is a set of operations, that is executed as a single unit. These operations include DML operations that are responsible for querying records.
All the DML operations in a transaction get completed successfully or get completely rolled back if an error occurs even in saving a single record.
Q. Explain Developer Console?
- The developer console is an incorporated development tool that has a collection of tools. We use these tools for debugging, creating, and testing the applications in salesforce.org.
Q. What are some Apex best practices?
- Bulkify your code
- Avoid SOQL Queries or DML statements inside FOR Loops
- Avoid Hardcoding IDs
- Use of the Limits Apex Methods to Avoid Hitting Governor Limits
- Querying Large Data Sets
Q. Is it possible to edit Apex Class/Trigger in the Production Environment?
- No, it is not possible. We cannot directly edit the Apex Class/Trigger in the production environment. It can be done only in the Developer edition, sandbox org or the testing org.
Q. What are the ways to call an Apex Class in Salesforce?
- The various ways to call an Apex class in Salesforce are as follows:
- From a Developer Console
- Using Triggers
- From Visualforce Page
- With JavaScript Links
- From Home Page Components
- From Another Class
Q. What is Apex Test Coverage?
- The Apex testing framework generates code coverage numbers for the Apex classes and triggers, every time when one or more tests are run. Code Coverage denotes the number of executable lines of code in classes and triggers which is exercised by test methods.
Test methods are written and tested to generate the Code Coverage. It is calculated as a percentage of a covered line divided by a covered and uncovered line.
The minimum test coverage must be 75 % for deployment in the production org.
Q. What are the types of Collections in Apex? Explain List and Set in Collections.
- The types of collections in Apex are listed below:
- List - A list is an ordered collection of elements that are distinguished by their indices. List elements can be of any data type : primitive types, collections, sObjects, user-defined types, and built-in Apex types.
- Map - A map is a collection of key-value pairs where each unique key maps to a single value. Keys and values can be any data type : primitive types, collections, sObjects, user-defined types, and built-in Apex types.
- Set - A set is an unordered collection of elements that do not contain any duplicates. Set elements can be of any data type : primitive types, collections, sObjects, user-defined types, and built-in Apex types.
Q. How to get the UserID of all the currently logged in users using Apex code?
- You can get the ID’s of all the currently logged in users by using this global function:
UserInfo.getUserId()
Q. Can we move our class from one sandbox to another if we don't have 75% code coverage?
- We can move a class from a sandbox to another even if we don't have the minimum code coverage. But if you want to move from sandbox to production then you must have 75% minimum code coverage.
Q. What is Apex Managed Sharing?
- Apex Managed Sharing provides developers with the ability to support an application to share requirements.
- This type of sharing is available only with users to modify all data permissions. Only these users can add/change apex-managed sharing.
- Apex Managed Sharing uses a Sharing reason (Apex Sharing Reason)
Q. What are Primitive Data Types?
- Integer, Double, Long, Date, Date-Time, String, ID, Boolean, etc., are some of the examples of primitive data types. These are passed by value and not by reference.
Q. What does the Data Wrapper Class contain?
- This contains abstract, structured and collection data.
Q. Is Return Type a must for a Method?
-Yes, the return type is a must for a method.
Q. What is the use of Debug Log?
- Debug Log is used for catching the exception.
Q. database.insert(ListForBulkDML, True) means what?
- Insert ListForBulkDML;
Q. How can we perform DML partially?
- If we want partially to happen, use a database.insert(list, false);
Q. What is SOQL?
- A query language that allows you to construct simple but powerful query strings and to specify the criteria that should be used to select the data from the platform database. SOQL Stands for Salesforce Object Query Language.
Q. What Are The Types of SOQL Statements in SalesForce?
- Salesforce Object Query Language is used to query records from the database.com based on the requirement.
There are 2 types of SOQL Statements:
- Static SOQL
- Dynamic SOQL
Static SOQL:
- The Static SOQL Statement is written in [] (Array Brackets)
- These statements are similar to IINQ (Ion Integrated Query)
Dynamic SOQL:
- It is used to refer to the creation of a SOQL string at run time with Apex code.
- Dynamic SOQL enables you to create a more flexible application.
- To create a Dynamic SOQL query at run time use a Database.Query() method, in one of the following ways.
- Return a single sObjects when the query returns a single record.
- sObjects s = Database. Query(String_limit_l);
- Return a list of sObjects when the query returns more than a single record.
Q. How many records can a select query return? How many records can a SOSL query return?
- The Governor Limits enforces the following:
- Maximum number of records that can be retrieved by SOQL command: 50,000.
- Maximum number of records that can be retrieved by SOSL command: 2,000.
Q. What is the difference between public and global class in Apex?
- Global class is accessible across the Salesforce instance irrespective of namespaces. Public classes are accessible only in the corresponding namespaces.
Q. What are getter methods and setter methods?
- Get (getter) method is used to pass values from the controller to the VF page.
The Set (setter) method is used to set the value back to controller variable.
Q. Can we write Setter and Getter methods in Salesforce?
- Yes, we use a getter method for returning the values for a controller. Each value computed by the controller and shown on the page should have a getter method.
and we use the setter method to pass the user-defined values from the page markup to the controller. In the controller, we execute the setter method automatically.
Q. How can we perform DML partially?
- If we want partially to happen, use a database.insert(list, false);
Q. database.insert(ListForBulkDML, True) means what?
- Insert ListForBulkDML;
Q. What is a Trigger?
- Apex triggers enable you to perform custom actions before or after events to records in Salesforce, such as insertions, updates, or deletions. Just like database systems support triggers, Apex provides trigger support for managing records.
Use triggers to perform tasks that can’t be done by using the point-and-click tools in the Salesforce user interface. For example, if validating a field value or updating a field on a record, use validation rules and workflow rules instead.
Q. What is the Apex Trigger in Salesforce?
- The trigger is an Apex Code that executes before or after. The following types of DML Operations:
- Insert
- Update
- Delete
- Merge
- Upsert
- Undelete
Q. What are The Types of Apex Triggers in Salesforce?
- Triggers are divided into 2 types
- Before Triggers
- After Triggers
Before Triggers:
Before Triggers can be used to update or validate values of a record before they are saved to the database.
After Triggers:
After Triggers Before Triggers can be used to access field values of the records that are stored in the database and use this value to make changes in other records.
Q. What are the various event on which a trigger can fire?
- A trigger is a set of statement which can be executed on the following events. In above trigger events one or more of below events can be used with comma separated.
- before insert
- before update
- before delete
- after insert
- after update
- after delete
- after undelete
Q. What are context variables in triggers?
- All triggers define implicit variables that allow developers to access run-time context. These variables are contained in the System.Trigger class.
Following are the context variable available in triggers. Please note variable availability in trigger varies according to the type of trigger events.
- isExecuting: Returns true if the current context for the Apex code is a trigger, not a Visualforce page, a Web service, or an executeanonymous() API call.
- isInsert: Returns true if this trigger was fired due to an insert operation, from the Salesforce user interface, Apex, or the API.
- isUpdate: Returns true if this trigger was fired due to an update operation, from the Salesforce user interface, Apex, or the API.
- isDelete: Returns true if this trigger was fired due to a delete operation, from the Salesforce user interface, Apex, or the API.
- isBefore: Returns true if this trigger was fired before any record was saved.
- isAfter: Returns true if this trigger was fired after all records were saved.
- isUndelete: Returns true if this trigger was fired after a record is recovered from the Recycle Bin (that is, after an undelete operation from the Salesforce user interface, Apex, or the API.)
- new: Returns a list of the new versions of the sObject records. This sObject list is only available in insert, update, and undelete triggers, and the records can only be modified in before triggers.
- newMap: A map of IDs to the new versions of the sObject records. This map is only available in before update, after insert, after update, and after undelete triggers.
- old : Returns a list of the old versions of the sObject records. This sObject list is only available in update and delete triggers.
- oldMap: A map of IDs to the old versions of the sObject records. This map is only available in update and delete triggers.
- size: The total number of records in a trigger invocation, both old and new.
Q. How is Trigger.New Different from Trigger.newMap?
- Trigger.New variable returns the list of sObject which has invoked the trigger and Trigger.NewMap returns the map of ID’s with the newly entered records. NewMap is only available in after insert, before and after the update and after undelete.
Q. Can a trigger call a batch class?
- Yes, we can call a batch class in the trigger as we do in the normal apex code.
Q. Define Recursive Trigger and how to avoid it?
- There is a possibility that the result of the trigger can end up calling the same trigger again and can run in a loop, this is known as a recursive trigger. To avoid this scenario we should create a static variable and check the value of this variable before we execute anything in the trigger.
Q. What is the Bulkification best practice?
- We must avoid using index values like Trigger.New[0] as we never know how many records we get in Trigger.New at runtime.
- We need to use it for each loop whether we have 1 record or many.
- We must not use SOQL inside for loop.
- We must not use SOSL inside for loop.
- We must not use DML inside for loop.
- We need to store data in collections, so our code will work for single as well as multiple records.
Q. What is the difference between trigger and workflow?
Workflow:
- Workflow is an automated process that fired an action based on Evaluation criteria and rule criteria.
- We can access a workflow across the object.
- We cannot perform DML operation on workflow
- We cannot query from database
Trigger:
- A trigger is a piece of code that executes before or after a record is inserted or updated.
- We can access the trigger across the object and related to that objects
- We can use 20 DML operations in one trigger.
- We can use 20 SOQL from the database in one trigger.
Q. What are the different types of Bindings?
- Following are the different types of bindings:
- Action Bindings: Action Bindings refers to action methods in the controller.
- Data Bindings: Data Bindings refers to the data sets in the controller.
- Component Bindings: Component Bindings refers to Visualforce components.
Q. What is Asynchronous Apex? What are its different types?
- Asynchronous Apex is used to run processes that are scheduled at a later time. There are four types of Asynchronous Apex.
Asynchronous Apex are:
- Future Methods
- Batch Apex
- Queueable Apex
- Schedules Apex
Q. What is Future Annotation(@Future)?
- Use the future annotation to specify that these methods are executed asynchronously.
- Methods with future annotation must be static methods
- Methods with future annotations can only return a void type.
Q. Explain various methods of batch Apex class?
- The batch apex class deploys the database batchable interface with the three methods as follows:
- Start
- Finish
- Execute
Start:
We use the start method at the beginning of the batch apex job. We use it for collecting the objects or records, for passing them to the interface for executing. It returns a DatabaseQueryLocator object that comprises objects or the records sent to the job.
Finish:
We call this method once we finish the batch processing. We use this method to send confirmation emails or to execute the post-processing operations.
Execute:
We use this method for every batch of the records that are sent to the method. We use this method for data processing. This method does the following:
- sObjects records list
- Reference to the DatabaseBatcheable context.
Q. What are the different methods of batch Apex class?
- Database.Batchable interface contains three methods that must be implemented:
Start method:
global (Database.QueryLocator | Iterable<sObject>) start(Database.BatchableContext bc) {}
Execute method:
global void execute(Database.BatchableContext BC, list<P>){}
Finish method:
global void finish(Database.BatchableContext BC){}
Q. Why do You write Test Classes?
- Test classes refer to the maximum lines of code covered when your execution takes place. If you want to develop a robust and error-free code, then the test classes are used as a tool for testing your code. It ensures that if any Apex customization has to be deployed in your org, then it will operate properly.
Every test class will be annotated with @isTestkeyword. In fact, we must annotate a test class with @isTest, for defining as a test class. If the keyword testMethod is used within any method within a class, then it is called as a test method.
Q. What is the Minimum Test Coverage that is required for Deployment?
- At least 75 % of your Apex code must be covered by unit tests in Salesforce, and all these tests must be completed successfully.
Q. What are the different ways of Salesforce Deployment?
- Salesforce code is deployed with:
- Salesforce packages
- Change Sets
- Com Migration Tools
- Eclipse with Force.com IDE
More Interview Questions and Answers adding soon... Keep Visiting. :)
Resources:
# Salesforce Admin Interview Questions and Answers
Comments
Post a Comment