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
Maddy123Maddy123 

Upsert with multiple external_id

Hi,
     I am upserting records in a custom object using Apex in Visualforce.
The custom object has columns i.e. CustName & Month which are together used as primary key to identify unique record in table. I am updating already existing records based on this combined key or inserting new  if table dont have such record.

Can I use two external Id's like follows to do same:

Upsert CustomerTab__c CustName__c , Month__c;

I am facing error like

ErrorError: Compile Error: Variable does not exist: Month__c at line 353 column 35

I have both variables having External Id option selected.

Anybody has any solution for this?

Thanks.
Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell
Upsert can only use a single external_id field. If you're using a compound key, then you'll need to store the compound version in its own field.

All Answers

SuperfellSuperfell
Upsert can only use a single external_id field. If you're using a compound key, then you'll need to store the compound version in its own field.
This was selected as the best answer
davcondevdavcondev

A child object can have two master-detail relationships. In data loader it is possible to specify an external id for each relationship when upserting child records.

 

Does this mean the equivalent is not possible in apex code?