You need to sign in to do that
Don't have an account?
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?
All Answers
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>
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.
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!!
Hi,
I need same requirement.
can u please provide apex class and vf code
Thanks in advance