+ Start a Discussion
Victor Mora 6Victor Mora 6 

New button override does not pre-populate the master detail detail field with the parent object record!

I created a visualforce page to override the new button of custom object called "Employment History" which is a child object to the standard contact object. I did this in order for the record name (in this case its called employment history name" will be pre-populated with the value "Default Value - IGNORE" so that I could update it with some concatenated field values on the same record using a workflow field update.
I was able to override the new button with a custom visualforce page in order for the record name to be pre-populated but this prevented the master-detail field to the contact object called "Student" from being populated with the parent record when I went to click the new button on the related list located on the contact detail page.
Here is the code I used to override the new button

<apex:page standardController="Employment_History__c" action="{!URLFOR($Action.Employment_History__c.New, null, ['Name'='Default Value - IGNORE'], true)}" />

I would really appreciate it if someone could explain to me how I can set the master detail field on the employment history object equal to the contact ID of the parent contact record.
GarryPGarryP
In ideal world if a new record is created using the related list of child object (in a master detail relatioship), the parent Field is automatically populated automatically.What is the need of overriding the New button with the VF page to autopopulate the parent field. i might be missing business use case

can you please elaborate what are you trying to acheive here?
or you wnat to populate just Some field in the child record whenever user clicks on NEW button in related list?
Victor Mora 6Victor Mora 6
@Girish P "or you want to populate just Some field in the child record whenever user clicks on NEW button in related list?" Yes that is exactly what i'm trying to acheive! When a user clicks on the new button for the related list on the detail page of the contact parent object the contact master detail field should be automatically populated with the parent contact id. The bussiness case is that I want to automatically create a custom record name using a workflow rule and in order to do that I have to input a default value into the record name first so it can be updated using a workflow. Doing this however removes the ability of the page to auto-populate the contact master-detail field. 
GarryPGarryP
ok got it.
in other workds the need is (what i understood)
  1. user clicks on New button in Related list of Child object.
  2. a new window should be opened up
  3. Pre-populate the Parent Object i.e parent contact record
  4. any generic Name should be autopopulated as well, coz Name field is (might be) required in the object.
  5. Record is saved
  6. Workflow is triggered
Solution-
You can acheive this using URL hacking, however this may not work in SF1 or lightning if at all you are using those things. If you are using the Salesforce 1 or lightning than approach would be diiferent.

Here is the solution, assuming SF1 and lightning is not being used
1. Get the first three letters of CHILD OBJECT (just got to any record and lookput at URL)
2. see the image below and create a custom button like this.
REPLACE "PUT_FIRST_THREE_LETTERS_OF_CHILD_OBJECT_GRABBED_AT_STEP1" text in the image by vlaue obtained in #1
User-added image
3. Save the button
4. Edit parent Object Layout
5. Add button in related list.

Save and try, this should work!
sharath jallu 9sharath jallu 9
Any approach for the same in lightning??