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
David_WuDavid_Wu 

Error:“Cannot specify both an external ID reference Account__r and a salesforce id, Account__c”

Hi,All.
   I created a new object type(such as objectA)  that had one field(such as account__c) to refer to some account.When I called API to change one objectA to refer to another account,there was a error:"Cannot specify both an external ID reference Account__r and a salesforce id, Account__c".
   code like that(C#):
         //the old value of objectA.Account__C is accountA,now set it accountB
         objectA.Account__c = accountB.Id;
  
   What is my problem?How to solve it?
   Thanks.


SuperfellSuperfell
account__c is the foreignKey field, this contains a string id value. account__r is the materialization of this FK, and contains an account object. you're calling update and have specified both account__c and account__r, and the server doesn't know which one it should pay attention to.
David_WuDavid_Wu
The new code  is:
        objectA.Account__r = null;
        objectA.Account__c = accountB.Id;


NO error.

Thanks.
praveen A 6praveen A 6
Hey David your post saved my time thanks!!!!!
Balayesu ChilakalapudiBalayesu Chilakalapudi
Thank you David_Wu.
Avinash Khanwaria 33Avinash Khanwaria 33

Hi,

I'am working on a dynamic deep clone funcionality and I'am getting the same error saying 'INVALID_FIELD, Cannot specify both an external ID reference FSLABB_Section__r and a salesforce id, FSLABB_Section__c:'.

In my case I have to specify the FSLABB_Section__r but needs to get rid of FSLABB_Section__c.

I tried emtying the value of FSLABB_Section__c by FSLABB_Section__c = null ;
But it is not working .

Can you please help?

Paul Payne 14Paul Payne 14
@Avinash Did you get the reverse scenario to work, I am having the same issue.
Praveen Krishna 1Praveen Krishna 1
Hope this helps.
Create a temporary obect reference of your child again, and specify your FSLABB_Section__r.
Code would be something like this.

Child object : FSLABB_SectionChild__c,
Parent Object: FSLABB_Section__c

FSLABB_SectionChild__c tmp = FSLABB_SectionChild__c();
tmp.id = FSLABB_SectionObj.id; // Orignal child record object which you are working;
tmp.FSLABB_Section__r = new FSLABB_Section__c(ExternalIdfield='XXXXXXX');

upsert tmp;