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) to 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.

  • Why a VF page, just use the standard URL Hack that has been talked about for years: salesforce.stackexchange.com/questions/147989/url-hack-question – Eric Dec 6 '16 at 4:33
  • It seems to me that this URL hacking requires that you create a brand new button. I want to override the standard new button on the Employment history object so that the resulting page has the record name and the master-detail to contacts pre-populated. I'm not able to remove the new button to replace it with a custom button. I got the idea from this page salesforce.stackexchange.com/questions/36281/… – Victor Mora Dec 6 '16 at 4:58
  • Is there a way I can include a url hack in a visualforce page? or some other way I could do this? – Victor Mora Dec 6 '16 at 5:25

You need to assign the parent Id and Name

{!URLFOR($Action.Employment_History__c.New, null, ['Name'='Default 
Value - IGNORE', CF00NE0000002aLV0_lkid=Parent_Object_Name__c.Id , CF00NE0000002aLV0=Parent_Object_Name__c.Name], true)}"

SO here CF00NE0000002aLV0_lkid will be your lookup Id in a new standard page.

You have to inspect the lookup field and get the name from the input tag.

For more info check this post http://raydehler.com/cloud/clod/salesforce-url-hacking-to-prepopulate-fields-on-a-standard-page-layout.html

  • Thank you for the update! However I get the error message "Error: Syntax error. Missing Unknown token: 23" whenever I try to save my code. Here are all the different kinds of code I tried based on your response and the link you provided. – Victor Mora Dec 6 '16 at 10:43
  • <apex:page standardController="Employment_History__c" action= "{!URLFOR($Action.Employment_History__c.New, null, ['Name'='Default Value - IGNORE', CF00NE0000002aLV0_lkid= Contact__c.Id , CF00NE0000002aLV0= Contact__c.First_Name + Contact__c.Last_Name], true)}" /> Please help if you can – Victor Mora Dec 6 '16 at 10:53
  • <apex:page standardController="Employment_History__c" action= "{!URLFOR($Action.Employment_History__c.New, null, ['Name'='Default Value - IGNORE', CF00N4100000HuU1K_lkid= {Contact__r.Id} , CF00N4100000HuU1K= {Contact__c.First_Name} + {Contact__c.Last_Name} ], true)}" /> – Victor Mora Dec 6 '16 at 10:57
  • @VictorMora try this {!URLFOR($Action.Employment_History__c.New, null, ['Name'='Default Value - IGNORE', CF00N4100000HuU1K_lkid= Contact__r.Id, CF00N4100000HuU1K= Contact__c.Last_Name__c ], true)} – Ratan Paul Dec 6 '16 at 11:14
  • I keep getting this error "Error: Syntax error. Missing Unknown token: 23" :( – Victor Mora Dec 6 '16 at 11:45

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.