External-ID Upsert vs Custom Idempotency Table for Retry-Safe Writes in Salesforce
Context When Apex callouts or asynchronous jobs fail transiently and are retried, the same logical write can execute multiple times. Two documented patterns prevent duplicate records: marking a field as an External ID and using upsert , or maintaining a custom Idempotency Key object that stores a hash of the request payload with a processed flag. Trade-offs