You are currently viewing Salesforce Developer Interview Questions Part3

Salesforce Developer Interview Questions Part3

Salesforce Developer interview Questions – Apex Continued

APEX (Continued)

35. Is there any other way we can enforce security apart from the “with sharing” keyword? Or How to enforce security to a specific method or lines of code instead of the whole class?

Answer:

We can use the following methods to enforce object level and field level security in apex code

  1. isAccessable
  2. isCreatable
  3. Isupdatable
  4. isDeletable

Example:


36. What are custom settings?

Answer:

  • Custom settings are similar to custom objects. Developers can create a custom set of data and associate custom data for an organization or profile or for a specific user.
  • All custom settings data is exposed in the application cache, which enables efficient access without the cost of repeated SOQL queries to the database.
  • Formula fields , validation rules , flows, apex, and SOAP API can use this data.

Example:

  • A shipping application requires users to fill in the country codes for international deliveries. By creating a list setting of all country codes, we can have quick access to this data without needing to query the database.

37. How many types of custom settings are there?

Answer:

There are two types of custom settings available.

  1. List Custom settings
  2. Hierarchy Custom settings

38. What is Hierarchy Custom settings?

Answer:

Hierarchy custom settings use a built-in hierarchical logic that lets us “personalize” settings for specific profiles or users.

The hierarchy logic checks the organization, profile, and user settings for the current user and returns the most specific or “lowest” value.

Example:

We have stored some data in custom setting, and we want to show the data based on users’ profile then we can use hierarchy custom settings


39. What are Custom metadata or custom metadata types?

Answer:

Custom metadata is similar to custom setting or object, but the only difference is the data stored in custom metadata is also in the form of metadata.

A custom metadata type is an object that is used to define the structure for application metadata. The fields of customer metadata types, and the values in the fields, consist only of metadata. The records of custom metadata type are also metadata.


40. What is the advantage of custom metadata over custom settings? Or what is the difference between custom metadata and custom settings?

Answer:

Custom metadata stores data or records in the form of metadata so it is very handy or easy to migrate from one org to another org. Custom metadata can be migrated to other orgs using any salesforce deployment tools.

Whereas Custom setting stores data in the form of data and its structure and field are in the form of metadata so its structure and field can be deployed to the other orgs using deployment tools, but its data should be uploaded using any data loader tools separately as any other data.


41. What are custom labels?

Answer:

Custom labels are custom text values that can be accessed from apex classes, Visualforce pages, Lightning components. Any field labels or error message are written in custom labels instead of hardcoding

Custom labels are generally used for two things in real time.

  1. To avoid hard coding in the apex code, or visual force or Lightning components
  2. To create multilingual applications

42. What is an anonymous Block?

Answer:

An anonymous block is apex code that doesn’t get stored in the metadata, but that can be compiled and executed.

If we want to run an ad hoc code and see the output we can use an anonymous window.

Goto → Developer Console → Debug → Open Execute Anonymous Window


43. Can you write a for loop to iterate a list of 10 accounts and set the Rating field to hot?

Answer:


44. What is an apex class or a class?

Answer:

Similar to java , we can create classes in apex. A class is a template or blueprint from which objects are created.

Here the object is an instance of a class.


45. What are access modifiers we use for apex classes ?

Answer:

  • Private
  • Public
  • global

46. Explain more about private access modifiers?

Answer:

Private :

  • This is the default access modifier for inner class. I.e. if we don’t specify any access modifier for an inner class, it is considered Private.
  • Top level classes can have either public or global but cannot have private access modifiers.
  • Top level classes can have a private access modifier if it is used with @isTest annotation.

47. Explain more about public and global access modifiers?

Answer:

Public :

  • Public class is visible in the application or namespace.

Global :

  • global class is visible everywhere in the org.
  • A class with webservice method must be declared as global.
  • If a method or inner class is declared as global then the outer , top-level class must also be defined as global.

48. What is a constructor?

Answer:

  • A constructor is a method which has the same name as the class name.
  • A constructor is a code that is invoked when an instance of a class is created.
  • A constructor is not mandatory to be created.
  • If a user doesn’t create a constructor, then a default constructor is created.
  • User defined constructor can be with arguments and without arguments.

49. What is the difference between static and instance methods in salesforce apex?

Answer:

A static methods are the methods which can be called without the instance of a class whereas instance methods are the methods which requires and instance of its class to be created before it can be called.

Example Static Method

This method can be called directly

String myCountry = UtilityClass.getCountry();

Example Instance Method

This method needs an instance to be created before calling

UtilityClass u = new UtilityClass();

String myCountry = u.getCountry();


50. What is interface?

Answer:

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

Leave a Reply