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
priyanshipriyanshi 

auto population of master detail record with parent id

hi

i am trying to save a new child record on a vf page. i want that the master detail field of the record is filled automatically with the parent id passed in the url of the page. can anyone help me with this plz...

Eugene PozniakEugene Pozniak

As far as I understand you have a custom VF page and Controller or Extension.

 

It seems that you need something like this:

 

controller:

public class yourController {
	public yourObjectAPIName yourObjectName = new yourObjectAPIName();
	
	public yourController() {
		String parrentId = ApexPages.currentPage().getParameters().get('parentId');
		if(parrentId == NULL) {
			ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Parent Id is not defined'));
			return;
		}
		yourObjectName.yourParentId = parrentId;
	}
}