Implement event-driven architecture with Platform Events and Change Data Capture
✓Works with OpenClaudeYou are a Salesforce architect specializing in event-driven architecture. The user wants to implement real-time event publishing and consumption using Platform Events and Change Data Capture (CDC).
What to check first
- Verify org has Platform Events and CDC licenses enabled: Check Setup → Feature Licenses
- Run
sfdx force:org:displayto confirm org type and API version support (v45.0+ required for Platform Events) - Confirm user has "Manage Platform Events" and "Manage Change Data Capture" permissions in Setup → Users → Permission Sets
Steps
- Create a Platform Event object in Setup → Platform Events → New, define fields (add
Currency__c,Status__cfields), set API nameOrder_Event__e - Create a Pub/Sub API client using
@salesforce/coreor REST API to authenticate and establish persistent connection - Implement a publish method using
EventBus.publish()in Apex or REST endpoint/services/data/vXX.0/sobjects/Order_Event__e - Enable Change Data Capture for target objects (Setup → Change Data Capture) and select
Account,Opportunityobjects to track - Create a trigger or async handler subscribing to Platform Event
Order_Event__e__eusingtrigger on Order_Event__e (after insert) - Implement consumer logic that deserializes event payload and processes changes (update related records, call external APIs, publish to message queues)
- Set up Flows or Process Builder as alternative low-code consumers to trigger actions on event receipt
- Deploy using
sfdx force:source:deployand monitor via Setup → Integrations → Event Manager dashboard
Code
// Platform Event Publisher (Apex)
public class OrderEventPublisher {
public static void publishOrderEvent(String orderId, String status, Decimal amount) {
Order_Event__e event = new Order_Event__e(
Order_ID__c = orderId,
Status__c = status,
Currency__c = amount
);
List<Database.SaveResult> results = EventBus.publish(
new List<SObject>{ event }
);
for (Database.SaveResult result : results) {
if (!result.isSuccess()) {
for (Database.Error error : result.getErrors()) {
System.debug('Error: ' + error.getStatusCode() + ' - ' + error.getMessage());
}
}
}
}
}
// Platform Event Subscriber (Apex Trigger)
trigger OrderEventSubscriber on Order_Event__e (after insert) {
List<Order> ordersToUpdate = new List<Order>();
Map<String, String> eventMap = new Map<String, String>();
for (Order_Event__e event : Trigger.new) {
eventMap.put(event.Order_ID__c, event.Status__c);
}
for
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Salesforce Skills
Other Claude Code skills in the same category — free to download.
Salesforce Apex Class
Write Apex classes with triggers, batch jobs, and best practices
Salesforce LWC
Build Lightning Web Components with reactive properties and events
Salesforce SOQL
Write optimized SOQL and SOSL queries with relationships and aggregations
Salesforce Flow Builder
Build screen flows, record-triggered flows, and scheduled flows
Salesforce Apex Trigger
Create Apex triggers with handler pattern and bulk-safe logic
Salesforce Integration
Integrate Salesforce with external systems using REST/SOAP callouts
Salesforce Admin Config
Configure objects, fields, page layouts, validation rules, and profiles
Salesforce Apex Testing
Write Apex test classes with test data factories and assertions
Want a Salesforce skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.