Salesforce Developer Interview Questions – Apex
Table of Contents
1. What is apex?
- 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?
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?
- 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?
- 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?
- Writing Code
- Compiling Code
- Checking performance
- SOQL Queries
- Color Coding and auto complete.
6. What are the other IDE or code editors you use as a salesforce developer?
- 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?
8.What are primitive data types?
The following are primitive data types
9. What are collections in salesforce?
10. What is an sObject?
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?
sObjects fields can be accessed or changed with simple dot notation
Account a = new account();
a.Name = ‘Acme’;
12. What are DML operations in apex?
Account a = new account();
13. What is single vs Bulk DML operation?
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?
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?
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.|