+ Start a Discussion

auto population of master detail record with parent id


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:



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'));
		yourObjectName.yourParentId = parrentId;