Home Salesforce Salesforce Apex Interview Question

Salesforce Apex Interview Question

by Dhanik Lal Sahni

Apex is a strongly typed, object-oriented programming language that allows developers to execute flow and transaction control statements on Salesforce servers in conjunction with calls to the API. Below are some of important questions.

You can also check below question posts for interview questions.

Salesforce Interview Question – Security
Top 20 Salesforce Interview Question – Integration

  1. What is difference between custom controller and controller extension?
    Ans.
    custom controller:
    Custom controller is required when standard controller is not fitting a requirement Like if you need to some custom validation or some external system call. We have to implements all of the logic for a page without leveraging a standard controller.controller extension:
    controller extension extends the functionality of a standard or custom controller. This is used when

    1. When we want to override any action like edit, view save or delete.
    2. When we want to add new action
  2. What is use of dynamic apex?
    Ans.
    There are number of use case of dynamic apex. Some of them are

    1. Showing record based on object selection on Page
    2. Copy records into other object based on dynamic configuration
  3. How to find list of classes in org?
    Ans.
    We can use object ApexClass to get list of all Apex Classes.

    Select Id, name from ApexClass
  4. How to find list of pages in Org?
    Ans.
    We can use object ApexPages to get list of all Apex pages.

    Select Id, name from ApexPage
  5. How to find list of triggers in Org?
    Ans.
    We can use object ApexTrigger to get list of all Apex trigger in org.

    Select Id, name from ApexTrigger
  6. Can we do overloading in Apex? If yes, how?
    Ans.
    Yes, we can do overloading in Apex.   We can do constructor and method overloading. Overloading support in giving different signature and implementation based on parameter.

    public class OverloadExample {
        integer height;
        
        //Constructor Overloading 
    	public OverloadExample()
        {
            height=0;
        }
        public OverloadExample(integer xNum)
        {
            height=xNum;
        }
        
        //Method Overloading
        public integer getHeight(integer x)
        {
            return x*x;
        }
        public integer getHeight(integer x, integer y)
        {
           return x*y;
        }
    }
  7. Why we have 15 and 18-character length record id?
    Ans.
    15 Character length id is case sensitive and 18-character id is case insensitive. Salesforce recommends to use 18-character ID. Lightning is using 18-character Id to view record page.We can remove last 3 character to get 15-character Id.
  8. Can we create Interface in Aped and How we can use it?
    Ans.
    Yes, we can create interface in Apex.

    interface IReqeuest {
         string getRequestNumber();
    }
    public class CaseRequest implements IReqeuest
    {
      public string getRequestNumber()
      {
        // Give your implemenation
         return '';
      }
     }
    
    
  9. How to retrieve record from recycle bin?
    Ans.
    We can use ALL Rows in SOQL.

    SELECT COUNT() FROM Contact WHERE AccountId = a.Id ALL ROWS
  10. How can we lock record using SOQL so that it cannot be modified by other user?
    Ans.
    For Update will lock record. Other user can not edit after records  are locked.

    Account [] accts = [SELECT Id FROM Account LIMIT 2 FOR UPDATE];

You may also like

3 comments

What is Light DOM - Salesforce Codex July 5, 2022 - 10:03 am

[…] Salesforce Apex Interview Question […]

Reply
What are Skinny Tables? - Salesforce Codex June 11, 2023 - 10:10 pm

[…] Salesforce Apex Interview Question […]

Reply
Questions for Tech Lead/Salesforce Architect Interview May 15, 2024 - 10:26 am

[…] Interview Question for Asynchronous ApexSalesforce Integration Interview QuestionsSalesforce Apex Interview QuestionTypes Of Integration Patterns in SalesforceDifference Between Custom Setting and Custom Metadata […]

Reply

Leave a Comment