Lesson 4: Advanced Salesforce Development Features
Lesson 4: Advanced Salesforce Development Features
1. Salesforce Flow Integration
Definition: Salesforce Flow automates processes with drag-and-drop logic.
Use: Simplify complex automation without code.
Example: Flow to auto-update Opportunity Stage based on probability.
trigger OpportunityStageUpdate on Opportunity (before insert, before update) {
for (Opportunity opp : Trigger.new) {
if (opp.Probability >= 75) opp.StageName = 'Closed - Won';
else if (opp.Probability < 25) opp.StageName = 'Prospecting';
}
}
Explanation:
Trigger.new
provides opportunities being modified.Logic updates
StageName
based onProbability
.Flow and trigger ensure seamless updates.
2. Platform Events
Definition: Platform Events facilitate real-time integration by streaming events to external systems.
Use: Notify systems of Salesforce changes.
Example: Publish an event when a new Contact is created.
trigger PublishContactEvent on Contact (after insert) {
for (Contact con : Trigger.new) {
Contact_Created_Event__e event = new Contact_Created_Event__e(ContactId__c = con.Id, Name__c = con.Name);
EventBus.publish(event);
}
}
Explanation:
Contact_Created_Event__e
defines the custom event.EventBus.publish
broadcasts it for subscribers.External systems receive real-time updates.
3. Asynchronous Apex (Future Methods)
Definition: Future methods execute code asynchronously, improving user performance.
Use: Process tasks in the background.
Example: Send emails after inserting Contacts.
public class ContactNotifier {
@future
public static void sendNotificationEmails(List<Id> contactIds) {
List<Contact> contacts = [SELECT Name, Email FROM Contact WHERE Id IN :contactIds];
for (Contact con : contacts) {
// Mock sending email logic
System.debug('Sending email to: ' + con.Email);
}
}
}
Explanation:
@future
marks the method for asynchronous execution.SOQL retrieves relevant contact details.
Mock email logic processes data efficiently.
Summary
Salesforce Flow Integration: Automate processes with minimal code.
Platform Events: Enable real-time external system notifications.
Asynchronous Apex: Execute background tasks for better performance.