You need to sign in to do that
Don't have an account?

first error: INVALID_FIELD, Foreign key external ID: tec.com not found for field abc_Email_ID__c
Requirement :- I have two objects Nomination__c and Participant__c. Hight level these object are related to Training.
Participants get nominated for Trainings. Nomination has capture all details of Participants so that if participants does not exist then it create new participants. abc_Email_ID__c is the field which we use to check if participant exist or not. "abc_Email_ID__c" is external id in Nomination and Participant__c.
I want ot use cascade inset functionality in Berfore Insert trigger on Nomination.Idea is insert Participant__c and associate atutomatically with Nomination when Nomination record is inserted.
Below is the sample code i am trying to run through Anonymous block when i am running it gives me following error
|System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD, Foreign key external ID: testing119@abc.com not found for field abc_Email_ID__c in entity Participant__c: []
Any idea why i am getting this error
code :-
Nomination__c nomiObj = new Nomination__c();
nomiObj.Employee_Name__c='testing119';
nomiObj.abc_Email_ID__c='testing119@abc.com';
nomiObj.Training_Name__c='a01Z000000O8EeS';
Participant__c partObj = new Participant__c();
partObj.abc_Email_ID__c=nomiObj.abc_Email_ID__c;
nomiObj.EmployeeID__r=partObj;
insert nomiObj;
Is the field 'abc_Email_ID__c' on Nomination__c a string? If it's a lookup field, 'testing119@abc.com' won't work as it isn't a valid record ID.
I dont think such a record is present and hence lookup fails and the code is throwing error.
Please check if you have a record with the above value
If you see my code -- line number 3, I am setting email address in nomination and with same email address i want to create Participant object. In line number 8 I am inserting nomination with the assumption that it will also insert Participant
1 Nomination__c nomiObj = new Nomination__c();
2 nomiObj.Employee_Name__c='testing119';
3 nomiObj.abc_Email_ID__c='testing119@abc.com';
4 nomiObj.Training_Name__c='a01Z000000O8EeS';
5 Participant__c partObj = new Participant__c();
6 partObj.abc_Email_ID__c=nomiObj.abc_Email_ID__c;
7 nomiObj.EmployeeID__r=partObj;
8 insert nomiObj;
You never inserted Paticipant in your code
The Idea is it is pretty straight forward
Nomination__c nomiObj = new Nomination__c();
nomiObj.Employee_Name__c='testing119';
nomiObj.abc_Email_ID__c='testing119@abc.com';
nomiObj.Training_Name__c='a01Z000000O8EeS';
insert nomiObj;
Participant__c partObj = new Participant__c();
partObj.Nomination__c = nomiObj.Id; //I am assuming Nomination__c is the api name of the lookup field from participant to nomination
insert partObj ;
". In line number 8 I am inserting nomination with the assumption that it will also insert Participant" do you have any link to this ? Kinda salesforce doc or blog, that states it is possible ?