Salesforce Developer Interview Questions – Apex
APEX
Table of Contents
1. What is apex?
Answer:
- Apex is a programming language developed by Salesforce, it is salesforce’s proprietary programming language and can be used only on Salesforce platform.
- Apex is a strongly typed, object-oriented programming language that allows developers to execute code on Salesforce platform.
- It also allows developers to write code to call API’s
- Apex syntax looks like Java or C# and acts like database stored procedures;
- It enables developers to add business logic to most system events, including button clicks, related record updates, and Visualforce pages.
- Apex code can be initiated by Web service requests and from triggers on objects.
2. When should we use apex?
Answer:
We use Apex if we want to:
- Create Web services.
- Create email services.
- Perform complex validation over multiple objects.
- Create complex business processes that are not supported by workflow.
- Create custom transactional logic (logic that occurs over the entire transaction, not just with a single record or object).
- Attach custom logic to another operation, such as saving a record, so that it occurs whenever the operation is executed, regardless of whether it originates in the user interface, a Visualforce page, or from SOAP API.
3.How does apex work?
Answer:
- All Apex runs entirely on-demand on the Lightning Platform. Developers write and save Apex code to the platform, and end users trigger the execution of the Apex code via the user interface.
- Apex is compiled, stored, and run entirely on the Lightning Platform
4.What is Developer Console?
Answer:
- Developer console is an integrated development environment (IDE)
- It is a collection of tools we can use to create, debug and test application in salesforce Org
5. What are the tasks supported by developer Console?
Answer:
- Writing Code
- Compiling Code
- Debugging
- Testing
- Checking performance
- SOQL Queries
- Color Coding and auto complete.
6. What are the other IDE or code editors you use as a salesforce developer?
Answer:
- Visual Studio Code
- Eclipse Force.com IDE
- Welkin Suite – Paid
- Illuminated Cloud (intelliJ Idea) – Paid
7. What are the different data types we have in salesforce?
Answer:
- Primitive
- sObject
- Collections
- Enum
8.What are primitive data types?
Answer:
The following are primitive data types
- Integer
- Double
- Long
- Date
- Datetime
- Sting
- ID
- Boolean
9. What are collections in salesforce?
Answer:
- List
- Set
- Map
10. What is an sObject?
Answer:
sObject refers to any object that can be stored in the salesforce platform database.
- Ex : Account, Lead, Opportunities, Invoice__c, payroll__c
- Ex: Account a;
- Ex: invoice__c inv;
Here “a” is an account sObject variable and “inv” is an invoice__c sobject variable
11. How to access sObjects fields?
Answer:
sObjects fields can be accessed or changed with simple dot notation
Ex:
Account a = new account();
a.Name = ‘Acme’;
12. What are DML operations in apex?
Answer:
- Update
- Insert
- Delete
Ex:
Account a = new account();
……
…….
Update a;
13. What is single vs Bulk DML operation?
Answer:
Updating one RECORD at a time is single dml operation whereas updating multiple RECORDS using list of sObject is Bulk DML operation
Ex : Single DML | Ex : Bulk DML |
Account a = new accountA.name = ‘Acme’Insert a;Account a = new accountA.name = ‘Google’Insert a; // Single DML | Account a = new account();list aList = new list();A.name = ‘Acme’aList.add(a);a.Name = ‘Google’aList.add(a);Insert aList; // bulk DML |
14. Which DML is recommended ? SINGLE or BULK?
Answer:
Performing BULK DML operations is the recommended way because it helps avoid hitting governor limits.
15. What is the difference between DML Statements vs Database Class Methods?
Answer:
Apex offers two ways to perform DML operations
Using DML Statements
Using Database Class Methods
DML statements are more straightforward to use and result in failure of all the records in case one record fails whereas with Database methods we can specify whether or not to allow for partial record processing if errors are encountered.
We can do so by passing an additional second Boolean parameter.
Ex : DML Statement | Ex : Database Class Methods |
Account a = new account();a.Name = ‘ACME1’;Insert a;Ex : DML StatementAccount a = new account();a.Name = ‘ACME2’;Insert a; | List aList = new List();alist.Add (new Account(Name =’acme1’));alist.Add(new Account (Name = ‘acme2’));Database.saveResult[ ] srList = Database.insert(aList, false);Here false allows partial insert if there is an error. |