You need to sign in to do that
Don't have an account?
Khaleel Shaik 9
Use Database.upsert with external id field is not working
Hi,
I need help to do a DML operation with external id field. I am using the below syntax, but it is throwing an error
Schema.SObjectField unique_projectuser = CC_Project_User__c.Fields.Unique_Project_User__c;
List<Database.UpsertResult> res = Database.Upsert(projectUsers_List, unique_projectuser ,false);
Error: getErrors=(Database.Error[getFields=();getMessage=Unique_Project_User__c not specified;getStatusCode=MISSING_ARGUMENT;]);getId=null
ANy help here is greatly appreciated. Thanks
I need help to do a DML operation with external id field. I am using the below syntax, but it is throwing an error
Schema.SObjectField unique_projectuser = CC_Project_User__c.Fields.Unique_Project_User__c;
List<Database.UpsertResult> res = Database.Upsert(projectUsers_List, unique_projectuser ,false);
Error: getErrors=(Database.Error[getFields=();getMessage=Unique_Project_User__c not specified;getStatusCode=MISSING_ARGUMENT;]);getId=null
ANy help here is greatly appreciated. Thanks
Please see below sample code.
You can define a field as an external id in Database.upsert..
List<Account> myaccounts = new List<Accounts> ();
//Say your external field is called Key__c
Schema.SObjectField f = Account.Fields.Key__c;
Database.UpsertResult [] cr = Database.upsert(myaccounts , f, false);
//then you can loop through results to identify the records that were created .
Hope this helps you!
Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution.
Thanks and Regards
Sandhya