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
magdamagda 

INVALID_FIELD, More than 1 field provided in an external foreign key reference in entity

Hi Every Body,

i try to insert a new Object having to other objects
Job application having candidate and position.

insert Canidate and insert Position is not a problem, but wenn i want to insert a job application i become this failure:

Insert failed. First exception on row 0; first error: INVALID_FIELD, More than 1 field provided in an external foreign key reference in entity: Position__c
My code is this one:
Code:
public Candidate__c getCandidate() {
if(candidate == null) candidate = new Candidate__c();
return candidate;
}
public Position__c getPosition() {
if(position == null) position = new Position__c();
return position;
}
public Job_Application__c getJobappl() {
if(jobappl == null) jobappl = new Job_Application__c();
return jobappl;
}
public PageReference save() {

jobappl.candidate__r = candidate;
jobappl.position__r = position;
insert position;
insert candidate;
insert jobappl;
}

 


Thanks for your help

Magda

steve_andersensteve_andersen
Looks like you're relating to a whole object. You should just relate to the Id.

You need to insert the candidate record before you can reference it. Something like:
insert candidate;
insert position;

jobappl.candidate__c = candidate.id;
jobappl.position__c = position.id;
insert jobappl;


magdamagda
Hi Steve

Thx very much it is runnung :)