ApexIntermediateupsertexternal-iddml
Optimize DML collections with upsert and external Id patterns
Real World Scenario
Nightly sync upserts 100k records using Database.upsert with external Id sometimes slower than expected.
Expected Answer
• External Id field indexed and unique per integration spec
• Batch upsert in chunks of 200 with partial success handling
• Separate insert vs update paths when majority are updates—query existing first
• Null external Id rows filtered before upsert
• Monitor duplicate rule interference on upsert
• Use Database.UpsertResult iterate errors per row
• Consider matching keys beyond external Id for composite match
Follow-Up Questions & Answers
Click to expand — each follow-up includes a direct, interview-ready answer
Direct answer: External Id field indexed and unique per integration spec Also consider: Batch upsert in chunks of 200 with partial success handling In practice: Separate insert vs update paths when majority are updates—query existing first Balance speed of delivery with maintainability.
Architect Perspective
Upsert performance depends on selective external Id index—validate before integration go-live.