+ Start a Discussion
jburnsSTjburnsST 

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)

 

window.open("/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!

 

JB

mikefitzmikefitz

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.