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

Passing variables to vf page from custom button

I have a custom list button on a related list which is displayed on a VF page,the button opens another vf page into an iframe . The page is opening fine in the iframe.


I am trying to pre-populate fields in the VF page:




Button code: (I tried it both with a ? and an & after quoteCreate)"/apex/quoteCreate?lead={!Lead__c.Name}",'q','height=450,width=650');

 I set the id of the input field in the vf page I am trying to populate to lead 


<apex:inputField id="lead" value="{!Quote__c.Lead__c}" required="false"/>

 but when I inspect the element using chrome it shows the NAME and ID as: j_id0:j_id2:j_id3:j_id12:lead


(which i have also tried using j_id0:j_id2:j_id3:j_id12:lead={!Lead__c.Name} this thows an error: The name 'quoteCreate&j_id0:j_id2:j_id3:j_id12:lead=L-0744' can only contain alphanumeric characters, must begin with a letter, and must be unique.)


So what i am trying to do is populate the field through my button code! someone please help!




Since you are using Visualforce, you should probably use Apex to capture the url parameters and populate your data.

This is pretty simple stuff but I would start by searching for the pagereference methods to understand how to consume parameters.



Good luck

Prafull G.Prafull G.

are you using custom controller (extension) for your visual force page "quoteCreate".

If yes, then you can do the initialization stuff in contructor itself.


Something like

String leadName = Apexpages.CurrentPage().getParameters().get('lead');  // this will return you whatever you passing on page as parameter

then user

Quote__c.Lead__c = leadName;


If you dont have any custom controller(extension) then probably you should check for the query string methods which will give you the lead value and then use DOM method to assign the value to your field.