Implement Salesforce Triggers
Add triggers to your Salesforce objects to enable RDN integration.
Trigger Overview
Triggers monitor your Lead and Contact records for changes and initiate the integration workflow. The RDNTriggerHandler class handles all the complex logic.
Lead Trigger
Create a trigger on the Lead object:
trigger LeadTrigger on Lead (after insert, after update) {
if (Trigger.isAfter) {
RDNTriggerHandler.handleTrigger(Trigger.new, Trigger.oldMap);
}
}
Contact Trigger
Create a trigger on the Contact object:
trigger ContactTrigger on Contact (after insert, after update) {
if (Trigger.isAfter) {
RDNTriggerHandler.handleTrigger(Trigger.new, Trigger.oldMap);
}
}
How It Works
Trigger Flow
- Record Updated - User creates or modifies a Lead or Contact
- After Trigger Fires - Trigger executes after record is saved
- Handler Invoked - RDNTriggerHandler.handleTrigger() is called
- Change Detection - Old and new values are compared
- Job Enqueued - If changes detected, Queueable job is enqueued
- Async Processing - Job runs asynchronously to avoid governor limits
- API Call - RDN API is called with configured fields
- Response Mapped - API response is mapped back to Salesforce
- Record Updated - Fields are updated with API response data
Trigger Execution Diagram

Important Details
warning
Change Detection: The old map and the new list are compared to identify any changes in the fields. An HTTP call will only be triggered if a change is detected in monitored fields.
What This Means
- If a field value hasn't changed, the integration won't run
- This saves API calls and processing resources
- Only changed records trigger integrations
Best Practices
1. Use After Triggers Only
// ✅ GOOD - After trigger ensures record is saved
trigger LeadTrigger on Lead (after insert, after update) {
if (Trigger.isAfter) {
RDNTriggerHandler.handleTrigger(Trigger.new, Trigger.oldMap);
}
}
// ❌ AVOID - Before triggers can't call APIs
trigger LeadTrigger on Lead (before insert, before update) {
// This won't work for API calls
}
2. Only Include Insert and Update
// ✅ GOOD - Only monitor creates and updates
trigger LeadTrigger on Lead (after insert, after update) {
// ...
}
// ❌ AVOID - Deletes/Undeletes usually don't need integration
trigger LeadTrigger on Lead (after insert, after update, after delete) {
// Only do this if you have a valid business need
}
3. Add Trigger Handlers for Multiple Objects
If you need to monitor Account, Opportunity, or other objects:
trigger AccountTrigger on Account (after insert, after update) {
if (Trigger.isAfter) {
RDNTriggerHandler.handleTrigger(Trigger.new, Trigger.oldMap);
}
}
Deployment
To Sandbox
- Create/modify trigger in your development org
- Deploy to Sandbox via Change Set or SFDX
- Test with sample records (see Testing Guide)
To Production
- Test thoroughly in Sandbox
- Create a Change Set including the trigger
- Deploy during maintenance window
- Monitor logs for the first hour after deployment
Troubleshooting
Trigger Not Firing
Check:
- Is the trigger active? (Setup → Apex Triggers)
- Is the object correct? (Lead vs Contact)
- Are you using
after insertorafter update?
Too Many API Calls
Solution:
- Make sure change detection is working
- Check that Trigger.oldMap is populated
- Review RDN logs to see which records triggered calls
Next Steps
- Allow Remote Sites - Configure Salesforce to allow API calls
- Testing - Run validation tests
Was this page helpful?