0 votes
1 view
in Salesforce by (11.9k points)

How does upsert work in the Salesforce API?

I believe that it checks it checks if there is a record with a unique id. In the case that it is available, then it updates the record otherwise the record is created.

Is this correct?

I am receiving the following 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 items, and there are no duplicate Asset_Tag values.

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})

What can I do to resolve this issue?

1 Answer

0 votes
by (32.1k points)
The error message symbolizes that, based on the External Id value you presented, there were two matching records. In this case, the system doesn't know which one it should update, so it fails.

If you take a look at /a11M0000000CwJqIAK and /a11M0000000CwJvIAK, they will have an identical value in the external ID field. You may want to reconsider de-duplicating the records for this object.

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...