I have a look as relationship between Parent Object and Child Object.

I am creating Child Object record first and creating the Parent Object record later using custom detail button on Child Object. So on the click of button on Child Object I am redirecting it to Parent Object record with some values pre populating from child object record to parent object record using url hack.

So after saving the parent object record I want the lookup field on child object to populate with parent object record Id.

Please explain to me how to update the lookup field (look up to parent record) on the child object record with parent object record id.

1 Answer 1


If you were happy to override the page for creating a new parent record with a Visualforce page, then you when you do the url hack you could also pass the Id of the child record. The controller of your Visualforce override page could then get this child Id and update the child record as follows:

ID childId ApexPages.currentPage().getParameters().get('childId');
Child_Object__c myChildObj = new Child_Object__c(Id = childId, Parent__c = parent.Id);
update myChildObj;

If you don't wish to override the new page then the only other way I can think of is creating a text field on the parent layout and passing the Id of the child via URL and populating the text field with this value. A trigger could then pick up the ID in this field and update the child similar to the previous option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.