Employee_c is a Child object of Company_c. The Company_c object has an external Id field Company_Id_c. How can a developer insert an Employee_c record linked to Company_c with a Company_Id_c of '999'?
A.
Employee_c emp = new Employee_c(Name='Developer'); emp.Company_r = '999' insert emp;
B.
Employee_c emp = new Employee_c(Name='Developer'); emp.Company_c = '999' insert emp;
C.
Employee_c emp = new Employee_c(Name='Developer'); emp. Company_c = new Company_c(Company_Id_c='999') insert emp;
D.
Employee_c emp = new Employee_c(Name='Developer'); emp.Company_r = new Company_r(Company_Id_c='999') insert emp;
As they are, none of them are correct, so if a typo is fixed, C seems to be the correct one:
Employee__c emp = new Employee__c(Name='Developer X');
[emp.Company__r = new Company__c(Company_Id__c='999');]
insert emp;
Employee__c emp = new Employee__c(Name='Developer');
Company__r = new Company__c(Company_Id__c ='999');
insert emp;
The above code works fine, therefore, all the given answers were not correct, it seems.
In option D, Company_r(Company_Id_c='999') it should be Company__c to work.
In Option C, emp.Company_c = new Company_c(Company_Id_c='999') it should be emp.Company_r on LHS for it to work.
C
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_nested_object.htm
upvoted 3 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
beardAnt
1 month, 1 week agosf2022
1 year, 11 months agomageshrr
2 years agoLiquad
3 years, 2 months agoHello_Sfdc
3 years, 8 months agoNiuNiuG
3 years, 9 months ago