+ Start a Discussion
ABakABak 

Passing Ids between visualforce pages.

I have a visualforce page with a standard controller set to a custom object. On click of a button on the page I am navigating to 2nd visualforce page. I would like to pass the 'Id' of the custom object to the second  page. Any ideas on whats the best way to do that?

Best Answer chosen by Admin (Salesforce Developers) 
WesNolte__cWesNolte__c

Oh so you're using an extension too? In that case it's easy, in your method that does this:

 

public PageReference standardPriceAddPage()

{ return Page.Add_Service_Standard_Price; }

 

Add this,

 

public PageReference standardPriceAddPage()

{

PageReference pr = Page.Add_Service_Standard_Price;

pr.put('id',serviceproduct.id);

return Page.Add_Service_Standard_Price;

 

}

 

Wes

All Answers

WesNolte__cWesNolte__c

Hey

 

Could you post some code, there are ways to do it but it depends on exactly what you're trying to do.

 

Wes

ABakABak

Heres my first apex page.

 

<apex:page standardController="Service_Product__c" extensions="ServiceProductsExtension" >
     <apex:detail />
     <apex:form >       
         <apex:pageBlock id="pbAddPrice" title="Add Price">
                 <apex:pageBlockButtons id="pbbtn" location="top">
                     <apex:commandButton id="btnAddPrice" value="Add Price" rendered="{!priceButtonActive}" action="{!standardPriceAddPage}"/>
                 </apex:pageBlockButtons>
          </apex:pageBlock>
     </apex:form>      
</apex:page>

 

 

 

 

On click of the button I want to switch to another page. the controller funciton for action on button

 

public PageReference standardPriceAddPage()

{ return Page.Add_Service_Standard_Price; }

 

Now I want to pass on the Id of the 'Service_Product__c' which is my custom object (hence the std controller) to the new page (which is 'Add_Service_Standard_Price') so that I can use DML on that new page.

WesNolte__cWesNolte__c

Oh so you're using an extension too? In that case it's easy, in your method that does this:

 

public PageReference standardPriceAddPage()

{ return Page.Add_Service_Standard_Price; }

 

Add this,

 

public PageReference standardPriceAddPage()

{

PageReference pr = Page.Add_Service_Standard_Price;

pr.put('id',serviceproduct.id);

return Page.Add_Service_Standard_Price;

 

}

 

Wes

This was selected as the best answer
ABakABak
thanks , that worked