What is an Object?
Standard Objects:
Custom Objects:
Student__c).Fields are the building blocks of an object, representing the data stored in it. Salesforce provides different field types for flexibility:
Scalar Fields:
Formula Fields:
Automatically calculate values based on other fields or formulas.
Example:
Formula: Calculate an employee's age from their date of birth:
TODAY() - Birthdate
Relationship Fields:
Project__c can have multiple employees and vice versa.Choose Field Types Wisely:
Avoid Deeply Nested Relationships:
What is Apex?
Variable Declaration:
Stores values for processing.
Example:
String name = 'John';
Integer age = 30;
Boolean isActive = true;
Control Structures:
Used for decision-making and iteration.
Examples:
if-else:
if (age > 18) {
System.debug('Adult');
} else {
System.debug('Minor');
}
for loop:
for (Integer i = 0; i < 5; i++) {
System.debug('Count: ' + i);
}
Data Structures:
List: An ordered collection of items.
List<String> names = new List<String>{'John', 'Jane'};
Set: A collection of unique items.
Set<Integer> uniqueNumbers = new Set<Integer>{1, 2, 3};
Map: Key-value pairs.
Map<Integer, String> students = new Map<Integer, String>();
students.put(1, 'John');
Static Methods:
Can be called without creating an instance of a class.
Example:
public class Utility {
public static void sayHello() {
System.debug('Hello, Salesforce!');
}
}
Encapsulation:
private: Only accessible within the class.public: Accessible anywhere.global: Accessible across all namespaces.What is a Trigger?
A Trigger automates actions in Salesforce when specific events occur, such as inserting or updating a record.
Example:
trigger AccountTrigger on Account (before insert, after update) {
for (Account acc : Trigger.new) {
acc.Description = 'Auto-updated description';
}
}
Best Practices:
Retrieves data from Salesforce.
Example:
SELECT Id, Name FROM Account WHERE Industry = 'Technology'
Performs full-text searches across multiple objects.
Example:
FIND 'Smith' IN Name Fields RETURNING Contact(Id, Name)
Why Governor Limits?
Examples of Limits:
Developer Console:
Salesforce CLI:
Visual Studio Code (VS Code):
Salesforce follows the Model-View-Controller (MVC) architecture, which is a design pattern used to separate application logic, data, and user interfaces. This ensures better organization, scalability, and maintainability of the system.
The Model represents the data and business logic of the application. In Salesforce, the data layer is composed of the following:
Account, Contact, Opportunity, and Case.Name, Email, Amount, etc.The View is responsible for displaying data to users and capturing user interactions. In Salesforce, this includes:
<apex> tags, often used for complex UI needs in Salesforce Classic.The Controller layer handles business logic and user interactions. In Salesforce, this consists of:
Security is a critical part of Salesforce development, ensuring that data is accessed only by authorized users. Apex security mechanisms include Field-Level Security (FLS), CRUD (Create, Read, Update, Delete) Permissions, and Sharing Rules.
Defines whether a user can Create, Read, Update, or Delete records in an object.
Best practice: Enforce CRUD checks in Apex to prevent unauthorized data access.
Example: Checking Read Access
if (Schema.sObjectType.Account.fields.Industry.isAccessible()) {
Account acc = [SELECT Industry FROM Account WHERE Id = :someId];
System.debug(acc.Industry);
} else {
System.debug('User does not have access to Industry field.');
}
Salesforce uses a record-level security model where users can access data based on ownership and sharing rules.
Example: Enforcing Sharing Rules in Apex
public with sharing class SecureAccount {
public static List<Account> getAccounts() {
return [SELECT Id, Name FROM Account]; // Enforces record-level security
}
}
Without Sharing Example (Avoid unless necessary):
public without sharing class AdminUtility {
public static List<User> getAllUsers() {
return [SELECT Id, Name FROM User]; // Ignores sharing rules
}
}
Asynchronous Apex allows operations to run in the background, preventing long-running processes from blocking user actions.
Best for short background tasks (e.g., external API calls).
Cannot return values.
Example:
public class AsyncExample {
@future
public static void processRecords(Set<Id> recordIds) {
List<Account> accs = [SELECT Id, Name FROM Account WHERE Id IN :recordIds];
// Process data asynchronously
}
}
Enhances Future Methods by allowing complex objects and method chaining.
Example:
public class QueueableExample implements Queueable {
public void execute(QueueableContext context) {
System.debug('Running Queueable Apex...');
}
}
To execute:
System.enqueueJob(new QueueableExample());
Best for processing large datasets (up to millions of records).
Example:
global class BatchExample implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator('SELECT Id FROM Account');
}
global void execute(Database.BatchableContext bc, List<Account> scope) {
for (Account acc : scope) {
acc.Name += ' - Updated';
}
update scope;
}
global void finish(Database.BatchableContext bc) {
System.debug('Batch Job Finished');
}
}
To execute:
Database.executeBatch(new BatchExample());
Salesforce provides multiple ways to deploy metadata between environments.
| Tool | Use Case |
|---|---|
| Change Sets | UI-based tool for small deployments |
| Salesforce CLI (SFDX) | For DevOps automation and CI/CD |
| GitHub Integration | Version control for source-driven development |
Salesforce DX (SFDX) is a powerful CLI tool for automating metadata deployment.
Example: Deploying metadata with SFDX
sfdx force:auth:web:login -r https://login.salesforce.com
sfdx force:source:push -u MyDevOrg
sfdx force:source:pull -u MyDevOrg
Continuous Integration/Continuous Deployment (CI/CD) automates deployments using tools like GitHub Actions, Jenkins, and Bitbucket Pipelines.
Example GitHub Actions Workflow:
name: Deploy to Salesforce
on: push
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Deploy to Salesforce
run: sfdx force:source:deploy -p force-app -u MyDevOrg
CI/CD Benefits:
Why does a trigger that loops through Trigger.new work, but querying the same records with SOQL inside the trigger may fail or behave differently?
Triggers should normally use Trigger.new instead of querying the same records again with SOQL.
Trigger.new contains the records currently being processed by the trigger. These records may not yet be committed to the database when the trigger runs, especially in before triggers. If a developer queries the database for those same records, Salesforce may return outdated or incomplete data because the transaction has not finished writing changes yet.
Using Trigger.new guarantees access to the correct in-memory version of the records. It also avoids unnecessary SOQL queries, which helps prevent hitting governor limits. Developers often mistakenly write queries inside triggers when the required data is already available in the trigger context variables. Best practice is to use Trigger.new, Trigger.old, and related collections for processing records.
Demand Score: 78
Exam Relevance Score: 88
When should a developer use a Validation Rule instead of Apex or Flow?
Use a Validation Rule when enforcing simple data validation logic on a record.
Validation Rules are declarative tools designed to enforce data integrity conditions without writing code. If the requirement is simply checking field values (for example, preventing an Opportunity from closing without a required field), a Validation Rule is usually the most efficient solution.
Using Apex or Flow for basic validation introduces unnecessary complexity and maintenance overhead. Validation Rules execute quickly and are easy for administrators to maintain. Apex triggers should be reserved for complex logic such as multi-object updates, integrations, or calculations that declarative tools cannot handle. Flows are best for orchestrating multi-step automation processes.
Choosing the simplest solution first is a key Salesforce development principle often tested on the PDI exam.
Demand Score: 70
Exam Relevance Score: 85
Why should developers avoid performing DML operations inside loops in Apex?
Because performing DML inside loops can exceed Salesforce governor limits.
Salesforce enforces strict governor limits to ensure fair resource usage across its multi-tenant platform. One of these limits allows only 150 DML operations per transaction. If a developer places insert, update, or delete statements inside a loop, the code may execute a DML operation for each record processed.
For example, processing 200 records could trigger 200 DML operations, exceeding the limit and causing a runtime exception. The recommended pattern is bulkification: collect records into a list during the loop and perform a single DML operation afterward.
Bulkification ensures the code works efficiently for both single records and large batches processed by triggers, API calls, or data loads. This concept is fundamental in Salesforce development and appears frequently in certification questions.
Demand Score: 75
Exam Relevance Score: 92
Why is understanding Salesforce Order of Execution important for developers?
Because it determines how automation tools interact and execute when a record is saved.
Salesforce executes multiple automation tools in a defined sequence whenever a record is created or updated. This sequence includes validation rules, triggers, workflows, flows, and assignment rules.
If developers do not understand this order, they may experience unexpected behavior such as triggers firing twice, validation rules blocking updates, or workflows modifying fields after triggers run. For example, a workflow field update can cause triggers to execute again within the same transaction.
Understanding the execution order helps developers design reliable automation and avoid recursion or unintended updates. It also helps when debugging complex automation involving multiple tools like Flow and Apex triggers.
Demand Score: 66
Exam Relevance Score: 83