Salesforce Interview Question

Salesforce Interview Question – Part 2

1. What is an interface in apex?

Ans. An interface is like an Apex class in which none of the methods has been implemented. It only contains the method signatures, but the body of each method is empty.

For e.g

global class ScheduleUpdate implements Schedulable{
    global void execute(SchedulableContext SC){}

2. What is the use of @Api in the Lightning web component?

Ans. It is used to expose a variable or functions publically and make properties reactive.

3. What is the syntax of Schedulable class?

Syntax of schedulable class:

global class ScheduleUpdate implements Schedulable
    global void execute(SchedulableContext sc) {
        // Implement any logic to be scheduled
        // We now call the batch class to be scheduled BatchContactUpdate b = new BatchContactUpdate ();
        //Parameters of ExecuteBatch(context,BatchSize) database.executebatch(b,200);

4. How can I resolve the mixed DML Error?

Ans. When the mixed DML Error is getting then we need to resolve this error using a future method or call asynchronously because this error will show when we perform an operation between the setup of the non-setup object.

5. What is the process of deployment?

Ans. Process of Deployment -> To deploy the changes from sandbox to prodction using change set.
For more know about deployment, please follow this link: Deployment Process in Salesforce

6. What is the sandbox and the type of sandbox?

Ans. A sandbox is a copy of the production environment/org, used for testing and development purposes.
Types of Sandboxes are:

  • Developer
  • Developer Pro
  • Partial Copy
  • Full

For more learn about the sandbox, please follow this link: Sandbox Tutorial

dont miss out iconCheck out the Salesforce Interview Question – Part 1 - HERE!

7. When do we use @TestVisible in the test class?

Ans. Use the TestVisible annotation to allow test methods to access private or protected members of another class outside the test class. These members include methods, member variables, and inner classes. This annotation enables a more permissive access level for running tests only.

8. Can you edit an apex trigger/apex class in a production environment? Can you edit a Visualforce page in production environment?

Ans. No, it is not possible to edit apex classes and triggers directly in a production environment.

9. Difference between Role and Profile?

Role Profile
The role helps in defining data visibility for a particular user. A profile sets the limitation for what an user can do in the organization.
Based on the hierarchy, a role defines which user data a user can see. Profile defines permissions
Defining role to a user is not mandatory Defining profile is mandatory
Roles provide a feature to control access to records by impacting reports. Profiles help to decide record privileges.

10. How to optimize your code?

  • Avoid SOQL Queries or DML statements inside FOR Loops
  • Bulky/triggers your Code
  • Bulky your Helper Methods
  • Using Collections, Streamlining Queries, and Efficient for Loops (Use maps and avoid nested for/do-while loops)
  • Comments, lots of comments to easy understandable any other developer
  • Use of the Limits Apex Methods to Avoid Hitting Governor Limits

11. What types of operations can be performed on multiple objects in a single DML statement?

You can perform the following operations on multiple objects in a single DML statement:


12. Why should we avoid SOQL queries inside FOR loops?

Ans. One of the main reasons to avoid SOQL queries inside FOR loops is because

  • it can lead to governor limits being reached.
  • This can cause your code to fail and can cause performance issues. Additionally, it can make your code more difficult to read and maintain.

13. What are the different ways of invoking Apex methods?

Ans. There are four ways of invoking Apex methods: from a Visualforce page, from an Apex controller or extension, from a trigger, or from a class that implements an interface.

14. What type of exception can be thrown as part of a trigger invocation?

Ans. A trigger can throw a System.Exception, which includes a number of different types of exceptions, such as DmlException, QueryException, and EmailException.

15. How many triggers can be associated with an object in Salesforce?

Ans. There can be up to 10 triggers associated with an object in Salesforce.

dont miss out iconDon't forget to check out: LWC Interview Questions -1 ( Freshers)

16. What are different type of Triggers?

Ans. There are two types of triggers:

  • Before triggers are used to perform a task before a record is inserted or updated or deleted. These are used to update or validate record values before they are saved
    to the database.
  • After triggers are used if we want to use the information set by Salesforce system and to make changes in the other records. are used to access field values that are set by the system (such as a record’s Id or LastModifiedDate field), and to affect changes in other records. The records that fire the after trigger are read-only.

17. What do you understand about workflow in Salesforce?

Workflow allows automation of standard internal processes for saving time across an organization. It helps in evaluating records as they are created or updated. It also determines whether an automated action must occur, such as functions like follow-up emails, marketing activities, tracking the customer map journey, and more.

A workflow rule is a container for various workflow instructions, usually summed up in an if/then statement.

18. What is Apex in Salesforce?

Apex is a strongly typed OOP language that allows developers to execute transaction control statements and flow on Salesforce platform servers in conjunction with calls to the API. Its syntax is similar to Java and serves as database stored procedures. The code can be initiated via triggers on objects and requests from web services, and they run on the Lightning platform.

Apex enables developers to incorporate business logic to system events, including button clicks, Visualforce pages, and related record updates.

19. What is the difference between public and global?

The public access modifier declares that this class is visible in your application or namespace. The global access modifier declares that this class is known by all Apex code everywhere

20. What is the difference between Aura and LWC?

There is a particular difference between Aura and LWC. The LWC-based lightning component is built using web stack tools, whereas the aura-based lightning components are built using HTML5 and JavaScript tools.

21. What are lifecycle hooks in LWC ?

Ans: A lifecycle hook is a callback method triggered at a specific phase of a component instance’s lifecycle.

There are following hooks supported in LWC :

Constructor : Called when the component is created.

Connectedcallback : Called when the element is inserted into a document. This hook flows from parent to child.

RenderedCallback : Called after every render of the component. This lifecycle hook is specific to Lightning Web Components, it isn’t from the HTML custom elements specification. This hook flows from child to parent. Ie its not part of HTMLElement rather defined in LightningElement.

Disconnectedcallback : Called when the element is removed from a document. This hook flows from parent to child.

Errorcallback  : Called when a descendant component throws an error. The error argument is a JavaScript native error object, and the stack argument is a string. This lifecycle hook is specific to Lightning Web Components, it isn’t from the HTML custom elements specification

22. How can call the Batchable class using future Methods?

Ans. Database.execute(BatchableClass, 200);

23. What is the Order of Execution in LWC?

  • constructor
  • wire
  • connectedCallback
  • render
  • renderedCallback
  • wire
  • render
  • renderedCallback

24. What is the difference Between Esclation Rule and Assignment Rule?

Ans. Assignment Rules applies for leads or cases. Escalation Rules applies for cases.

25. What is the Asynchronous Apex?

Ans. Asynchronous Apex is used to run processes in a separate thread, at a later time. An asynchronous process is a process or function that executes a task “in the background” without the user having to wait for the task to finish.

26. What is the Validation Rule?

A validation rule is one way to restrict input in a table field or a control (such as a text box) on a form. Validation text lets you provide a message to help users who input data that is not valid.

dont miss out iconCheck out another amazing blog by Aman here: What is Enhanced Domain Security in Salesforce in 2023?

27. How to get the Current Login User?

Ans. To get the current login user using this userinfo.getuserinfo();

28. How many types of events in trigger?


Salesforce Interview

29. What is the Difference Between trigger.old &

Ans. Trigger.New variable returns the list of sObject which has invoked the trigger and Trigger.old returns a list of the older versions of the records which have invoked the trigger. Trigger.Old is only available in update and delete events.

30. What is the Difference Between & trigger.newMap?

Ans. 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


Popular Salesforce Blogs