Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lfreeland/3289c941b3f7313cb8a088ccfef5190b to your computer and use it in GitHub Desktop.
Save lfreeland/3289c941b3f7313cb8a088ccfef5190b to your computer and use it in GitHub Desktop.
Upsert List<SObject> With ExternalId No AllOrNothing Error Example
public static List<Database.UpsertResult> upsertListSObjectsWithExternalIdNoAllOrNothingErrorExample() {
List<SObject> records = new List<SObject>();
Account a = new Account(
Name = 'Example Company',
External_Id__c = 'ExampleCompany'
);
records.add(a);
Schema.SObjectField f = Account.Fields.External_Id__c;
/* this throws a runtime exception of
* System.TypeException: DML on generic List<SObject> only allowed for insert, update or delete
*/
return Database.Upsert(records, f);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment