Created
May 12, 2016 12:16
-
-
Save lfreeland/3289c941b3f7313cb8a088ccfef5190b to your computer and use it in GitHub Desktop.
Upsert List<SObject> With ExternalId No AllOrNothing Error Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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