Created
May 25, 2015 10:30
-
-
Save EndritSino/710ef9cb4e8fdc43b148 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
* This code aims to test the Test Database.Upsert(SObject[] soList, Schema.SObjectField field, Boolean all_or_none) | |
* method. Described by this reference: http://www.salesforce.com/us/developer/docs/dbcom_apex250/Content/apex_dml_upsert.htm | |
* | |
* For the moment, the test fails, by retreiving the following error: "Upsert requires a concrete SObject type" | |
* ***Considerations: | |
* Please substitute the id values in the set accIds, with account IDs from your org. | |
*/ | |
// 1. Retrieve Accounts | |
Set<String> accIds = New set<String>{'001w000001JklMQAAZ', '001w000001DdXjG'}; | |
List<Account> al = [Select id, Name, Test_External_Id__c From Account where id in: accIds]; | |
System.debug('1. Al: ' + al); | |
// 2. Modifying values: | |
al[0].Name = 'Enver Hoxha'; | |
al[1].Name = 'Nexhmije Hoxha'; | |
System.debug('2. Al Updated: ' + al); | |
// 3. TypeCasting in Sobjects | |
List<SObject> soL = new List<SObject>(); | |
for(Account a: al){ | |
sol.add((SObject)a); | |
} | |
// 4. Tentando upsert | |
Schema.SObjectField field = Account.Fields.Test_External_Id__c; | |
Database.UpsertResult [] ups = Database.upsert(sol, field, false);// ***Code fails HERE | |
System.debug('4. Esito Upsert: ' + ups); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment