Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahulmalhotra/06eae3f6923cad6d176ef4d67a2e450b to your computer and use it in GitHub Desktop.
Save rahulmalhotra/06eae3f6923cad6d176ef4d67a2e450b to your computer and use it in GitHub Desktop.
This code snippet is used in First error: Insert/Upsert failed. First exception on row 100; first error: INVALID_FIELD, Cannot specify both an external ID reference Parent and a salesforce id, ParentId: [] salesforce tutorial to specify error when we're having both id of the parent object and reference populated as well.
List<SObject> records = new List<SObject>();
records.add(new Account(Name='Test Account', Reference_ID__c = 234));
records.add(new Contact(LastName='Test Contact', AccountId = null, Account = new Account(Reference_ID__c = 234)));
Database.upsert(records);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment