I have one similar problem asked here. But My Objects are Project(Parent) -- > Milestone(Child) --> Action(GrandChild)..

Deep Clone (Parent -> Child -> Grand Child)

I have tried using the External Id. But I am not sure how I will access Milestone.

This line of code..

newOpp.Account = new Account(ExternalId__c = accNew.ExternalId__c); //set parent ref

Here is the referencing Account, how can I do this for custom relations. How I can reference object instead of Id.

Project__c proj = new Project__c(ExternalId__c = newProj.ExternalId__c);
// when crating milestone
newMileStone.Project__c = proj;   // when i tried this, it says i have to pass id instead of project. 

If any one has done this before, I would like to get some inputs.

I have also tried @Avidev9's code. From that piece of code, there is something I couldn't understand completely. After inserting newOpportunityList, maps values are becoming null somehow. Tried debugging a lot. But no luck reaching the solution.

1 Answer 1


You use the "reference" object instead ("__r"):

newMileStone.Project__r = proj;

Make sure the object you're setting only has one field enabled, and it is an external Id field (as in your sample code).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .