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
CliffACliffA 

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) 
jwetzlerjwetzler
Hi Cliff.  This should now be working.  Can you please verify?

All Answers

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

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_Shift__c.name}"/> <!-- 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
jwetzlerjwetzler

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.

CliffACliffA

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.

 

 

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

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!!

swapna9swapna9

Hi,

 

I need same requirement.

 

can u please provide apex class and vf code

 

Thanks in advance