+ Start a Discussion
bbradybbrady 

Can I pass a field value from a standard page to a VF page?

I need to pass a field value (the id, in this case) of the object on a Standard Controller page to a VF page that uses a custom controller. I want to mimic the standard controller behavior that occurs when you click "new" in a relatedlist section - that being: the standard controller takes you to the screen to enter new data for the related list object, and the lookup field to the parent is already populated.

 

I currently have a New-button override that will launch the VF page, but I can't figure out how to pass it a parameter without building the originating page and controller from scratch.

Force2b_MikeForce2b_Mike

I'm not exactly sure how you have the pages and buttons, but one possibility is to use OnClick JavaScript for your button instead of pointing to a VisualForce page. In your JavaScript redirect to a URL that passes in the parent ID as a parameter

 

 

parent.document.location.href= "/apex/visualforcepage?ID={!contact.id}";

 

Mike

 

bbradybbrady

Thanks! that takes me a step in the right direction but what I need to do is pass a value to that VF page to pre-populate a field on the new page. My application won't have a record id for the new page at this point. My controller won't know what the contact.id is (to use your example) until the user clicks save.

 

Thanks for your help!

 

Bill

patrospatros
I think scrappydog's approach will work (passing the ID of the related object via querystring using Javascript). The constructor of your custom page's controller will need to create a new object and populate the MyObject__c.RelatedObject__c value with the querystring value coming in.