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

How do you pre-fill fields on a VisualForce page?

I have two custom objects with a parent/child relationship.  Using the standard SF pages, if I click on the "New [Child Object]" button in the related list section of the Parent record the new child record page comes up with the reference field to the parent pre-filled with the parent's name.


If, however, I override the "New [Child Object]" button to point to my VisualForce page for the child the Parent's reference field is not pre-filled with the parent's name.  I don't want to force my users to manually enter the parent's name as that's not consistent with standard SF pages plus it's a pain.


Is there a way to pre-fill fields on a VisualForce page in this scenario? 



Best Answer chosen by Admin (Salesforce Developers) 
Hi Cliff.  This should now be working.  Can you please verify?

All Answers

Has your instance been upgraded to the Spring '09 release yet?  I believe this is fixed in the new release.

Yes, our org has been upgraded.  For reference, here's the code in the VF page that references the field:


<apex:page standardController="Volunteer_Project_Shift__c" tabStyle="Volunteer_Project__c"> <apex:messages /> <apex:form > <apex:pageBlock title="Volunteer Project Shift"> <apex:pageblockbuttons > <apex:commandButton action="{!save}" value="Save"/> <apex:commandButton action="{!cancel}" value="Cancel"/> </apex:pageblockbuttons> <apex:pageBlockSection title="Shift" columns="2"> <apex:inputField value="{!}"/> <!-- Volunteer_Project__c is the reference to the parent --> <apex:inputField value="{!Volunteer_Project_Shift__c.Volunteer_Project__c}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>


Message Edited by CliffA on 02-13-2009 06:52 PM

Ahh, I just tested this out and it looks like it doesn't work for custom objects :(


You can always do this in an extension but I realize that's both a pain and something that's officially not supported (scraping the query parameters we pass in).  I will log a bug for myself.


Hi Jill,

Thanks for the quick reply, although it wasn't the response I was hoping for  :smileysad:


I'll see if I can get creative and come up with a workaround in the meantime.



Hi Cliff.  This should now be working.  Can you please verify?
This was selected as the best answer

I looks like it's working!  I was just getting ready to build some more VF pages and this will make my job much easier.


Thanks Jill!!




I need same requirement.


can u please provide apex class and vf code


Thanks in advance