function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
pradyprady 

how does upsert with external id work?

hi,

 

how does upsert work?

my understanding is that it checks if there is a record with unique id and if its available then it updates that record and if its not then inserts it.

 

Am i right?

 

I seem to get an error

Upsert failed. First exception on row 1; first error: DUPLICATE_EXTERNAL_ID, Asset Tag: more than one record found for external id field: [a11M0000000CwJqIAK, a11M0000000CwJvIAK]: [Asset_Tag__c]

 

i have a list with item and they dont have asset tag repeating in that

 

system.debug('LstItem Asset_Tag__c'+LstItem );
		upsert 	LstItem Asset_Tag__c;

 From the debug log

 

LstItem Asset_Tag__c(Item_c__c:{Scanned_By__c=005M0000000IlxyIAC, Asset_Tag__c=12149, Status__c=Active, Scan_Location__c=001M0000008GzJXIA0, Last_Scan_Date__c=2011-12-17 06:08:47}, Item_c__c:{Scanned_By__c=005M0000000IlxyIAC, Asset_Tag__c=23157, Status__c=Active, Scan_Location__c=001M0000008GzJXIA0, Last_Scan_Date__c=2011-12-17 08:26:14})

 You can see that the asset tags are not repeated. So i am not sure from where the duplicate external id is coming

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
Rahul SharmaRahul Sharma

Unique fields are unique to a record.

That means if you have one record in your database with Asset Tag value as 2400 then you can't create another record with same Asset Tag(2400).

what are these ids?

Upsert failed. First exception on row 1; first error: DUPLICATE_EXTERNAL_ID, Asset Tag: more than one record found for external id field: [a11M0000000CwJqIAK, a11M0000000CwJvIAK]: [Asset_Tag__c]

All Answers

Rahul SharmaRahul Sharma

Unique fields are unique to a record.

That means if you have one record in your database with Asset Tag value as 2400 then you can't create another record with same Asset Tag(2400).

what are these ids?

Upsert failed. First exception on row 1; first error: DUPLICATE_EXTERNAL_ID, Asset Tag: more than one record found for external id field: [a11M0000000CwJqIAK, a11M0000000CwJvIAK]: [Asset_Tag__c]
This was selected as the best answer
pradyprady

Hi Rahul,

 

Thanks for the pointer on the ids.. it turned out that there were 2 records already existing with same asset tag. Changed them to different asset tag and it worked now..