Part 8: Salesforce interview Questions (Apex)

71. What is the difference between public class vs Global class?

Public – Public class is accessible only in the corresponding namespace

Global – Global Class is accessible across the Salesforce instance irrespective of namespaces.

72. What are different access modifiers in Apex?


73. What is difference between with Sharing vs without Sharing?

Any class that has With Sharing will enforce the Sharing rules for the current user.

Any class that has without sharing specified or no sharing specified then it runs in the context of system admin mode/system mode.

Dev Tip 7: Difference between With Sharing and Without Sharing in Salesforce

74. What is the default value for class when sharing is not specified?

By default, every class runs in System mode or Admin mode if we do not specify any sharing keyword.

75.  What is the purpose of  extends keyword in salesforce?

A class that extends another class inherits all the methods and properties of the extended class. A class can only extend one other class, but it can implement more than one interface.

76. What is an Interface?

An interface is like a class in which none of the methods have been implemented—the method signatures are there, but the body of each method is empty. To use an interface, another class must implement it by providing a body for all of the methods contained in the interface.

77.  What is the purpose of final keyword?

Final variables can only be assigned a value once, either when you declare a variable or inside a constructor. You must assign a value to it in one of these two places.

78. What is the purpose of Dynamic Apex?

Dynamic Apex enables developers to create more flexible applications by providing them with the ability to:

Access sObject and field describe information

Access Salesforce app information

Dynamic SOQL and SOSL queries provide the ability to execute SOQL or SOSL as a string at runtime, while dynamic DML provides the ability to create a record dynamically and then insert it into the database using DML

79. How to access Recordtypeid dynamically without using soql query?

Id recordTypeId = Schema.SObjectType.Lead.getRecordTypeInfosByName().get(‘Record Type Name‘).getRecordTypeId();

In the Record type Name mention your desired record type Name that is available in your org.

80. How to get the sobject describe result through dynamic apex?

To access the describe result for an sObject, use one of the following methods:

  • Call the getDescribe method on an sObject token.
  • Use the Schema sObjectType static variable with the name of the sObject. For example, Schema.sObjectType.Lead.
  • Schema.DescribeSObjectResult is the data type for an sObject describe result.

    The following example uses the getDescribe method on an sObject token:

  • Schema.DescribeSObjectResult dsr = Account.sObjectType.getDescribe();

    The following example uses the Schema sObjectType static member variable:

    Schema.DescribeSObjectResult dsr = Schema.SObjectType.Account;


Related post