Connecting WordPress to Salesforce without duplicate records
Lessons from keeping an international platform in sync with Salesforce: identifiers, asynchronous sync, retries and how to clean duplicates without leaving orphaned records.
Connecting a website to Salesforce looks simple: a form sends data and a contact appears in the CRM. The trouble comes months later, with repeated contacts, wrongly linked accounts and nobody sure which system holds the right data. This is what I apply to avoid it.
Decide which system is the source of truth
For each piece of data, decide which system rules. For example: the user profile is edited on the website, but the account status is decided by the team in Salesforce. Without that rule, both sides overwrite each other.
Store the Salesforce Id on the website
When a record is created in Salesforce, I store its Id on the website (for example, in the user metadata). From then on, updates point to that record and no new one is created. If the record does not exist yet, I first search by a unique field, such as email or an external id, and use upsert instead of creating blindly.
Sync in the background, with retries
Calling Salesforce on every page load slows the site and fails when the API is slow. I prefer to queue the sync and process it with scheduled jobs:
- The user action finishes fast and the sync happens later.
- If the API returns an error, the job retries.
- Every attempt is logged so it can be reviewed.
A detail that took time to find: in WordPress, scheduled jobs run without a user. If the code depends on the current user, it must be set explicitly or the data arrives incomplete.
Monitor and reconcile
I set up a daily check that compares both sides and emails an alert if records are out of sync. Fixing ten records today is far cheaper than thousands a year from now.
Clean duplicates carefully
Deleting duplicates on the website can leave orphaned records in Salesforce if those duplicates were already synced. Before deleting, I check which ones have a Salesforce Id, decide which one to keep and merge on both sides. Always with a backup first and in a test environment first.
In short
One source of truth per field, the Id stored on the website, background sync with retries, daily monitoring and careful cleanup with backups. That way the CRM stays reliable over time.