Lesson 1: Salesforce Development Basics
Lesson 1: Introduction to Salesforce Development
1. Salesforce Object Query Language (SOQL)
Definition: SOQL retrieves records from Salesforce objects, similar to SQL in databases.
Use: Extract specific data efficiently.
Example: Fetching accounts with revenue above $1M.
List<Account> accounts = [SELECT Name, AnnualRevenue FROM Account WHERE AnnualRevenue > 1000000];
Explanation:
List<Account>
stores multiple Account objects.SELECT Name, AnnualRevenue
defines fields to retrieve.WHERE
filters accounts withAnnualRevenue > 1000000
.
2. Data Manipulation Language (DML)
Definition: DML modifies Salesforce data, including inserting, updating, or deleting records.
Use: Perform CRUD operations programmatically.
Example: Inserting a new Contact record.
Contact newContact = new Contact(FirstName = 'John', LastName = 'Doe', Email = 'john.doe@example.com');
insert newContact;
Explanation:
new Contact()
creates a Contact instance.FirstName
,LastName
,Email
set field values.insert
commits the new record to the database.
3. Apex Triggers
Definition: Triggers automate actions when specific events occur (e.g., insert, update).
Use: Enforce rules or sync data.
Example: Trigger to update Account fields after Contact insertion.
trigger UpdateAccountTrigger on Contact (after insert) {
for (Contact con : Trigger.new) {
Account acc = [SELECT Id, LastContactDate FROM Account WHERE Id = :con.AccountId LIMIT 1];
acc.LastContactDate = System.today();
update acc;
}
}
Explanation:
after insert
runs trigger post-insertion.Trigger.new
contains inserted records.update acc
saves updated Account.
Summary
SOQL: Query data with filters.
DML: Modify database records.
Apex Triggers: Automate Salesforce logic.