+ Start a Discussion
RICARDO PALMARICARDO PALMA 

How send a parameter to a controller after clicking a button

Hi,
I have a visualforce page that is going to call another visual force page after clicking a button in a <apex:pageBlockButtons >.
Where I click the button Enter Data the doUnlink function is executed and call a method in a another class. On that class I have a call to another visualforce page. The issue is that I'm tying to pass Prod.Id to used when calling the new visualforce page but for some reason the id is  not passing to the class.

Here is the part of the code 
<apex:actionFunction name="doUnlink" action="{!openPage}" rerender="refresh" />
<apex:pageBlockTable value="{!listProducts}" var="Prod">
         <apex:column headerValue="Click to add info">
        <apex:commandButton value="Enter Data" onclick="doUnlink();" >
        <apex:param id="oppProdId" value="{!Prod.Id}" assignTo="{!oppprorec}"/>
        </apex:commandButton>
    </apex:column>
    
</apex:pageBlockTable>
Thanks
 
Best Answer chosen by RICARDO PALMA
YogeshMoreYogeshMore
Hello Ricardo,

Past following VF code to your existing code.
<apex:page standardController="Opportunity"  sidebar="true" action="{!FetchData}" extensions="OppProductActivation" language="en-US" >

<apex:form id="form">
<apex:outputPanel id="tstid">
<apex:pageMessages />
</apex:outputPanel>

<apex:outputLabel value="Opportunity: "  style="font-size:10px; "/>
<apex:outputLabel value="{!Opportunity.Name }" style="font-weight:bold; font-size:20px; " />

<apex:pageBlock >
        <apex:pageBlockButtons >
        <apex:commandButton value="Return to Opportunity" action="{!cancel}"/> 
        </apex:pageBlockButtons> 
<apex:pageBlock title="Products">

<apex:pageBlockTable value="{!listProducts}" var="Prod">  
    <apex:column value="{!Prod.LastModifiedDate}"/>
    <apex:column value="{!Prod.ProductCode}"/>
    <apex:column value="{!Prod.id}"/>
    <apex:column headerValue="Click to add info">
    <apex:commandButton value="Enter Data" onclick="window.open('/apex/OppProductRecordActivationVF?id={!Prod.id}','_self');" reRender="form">
       
    </apex:commandButton>
    </apex:column>

  
    
</apex:pageBlockTable>
</apex:pageBlock> 
</apex:pageBlock> 
</apex:form>
</apex:page>

and there is no need of second controller name as "OppProductRecordActivation", you can delete that one. 
​If you go solution of your problem, then please mark this as best answer.


Regards,
YogRaj

All Answers

YogeshMoreYogeshMore
Hello Ricardo,

When you are calling another visualforce page then pass Prod.Id as a parameter in URL.
Example: - https://ap2.visual.force.com/apex/pageName?prodId=Prod.Id

after this get prod id in the constructor of newly open page controller by using following code.
 String prodId = ApexPages.currentPage().getParameters().get(' prodId ') ;

Regards,
YogRaj
RICARDO PALMARICARDO PALMA
Hi YogRaj, thanks for your response.
The issue is that my standardController="Opportunity" and the I have a pageBlockTable that is going to get some records from the OpportunityLineItem base on a condition. This infor comes from another controller. Once I have those product on my screen I need to send the opportunity product id to the new visualforce page to open or edit that particular product. The problem with String prodId = ApexPages.currentPage().getParameters().get(' prodId ') ; is that becuase my  standardController="Opportunity" and I trying to get id from OpportunityLineItem I'm getting and error.
 
YogeshMoreYogeshMore
Can you share your all code?
Because it will help to solve your issue.
RICARDO PALMARICARDO PALMA
Here is the VFP
<apex:page standardController="Opportunity"  sidebar="true" action="{!FetchData}" extensions="OppProductActivation,OppProductRecordActivation" language="en-US" >

<apex:form id="form">
<apex:outputPanel id="tstid">
<apex:pageMessages />
</apex:outputPanel>

<apex:actionFunction name="doUnlink" action="{!openPage}" rerender="refresh" />

<apex:outputLabel value="Opportunity: "  style="font-size:10px; "/>
<apex:outputLabel value="{!Opportunity.Name }" style="font-weight:bold; font-size:20px; " />

<apex:pageBlock >
        <apex:pageBlockButtons >
        <apex:commandButton value="Return to Opportunity" action="{!cancel}"/> 
        </apex:pageBlockButtons> 
<apex:pageBlock title="Products">

<apex:pageBlockTable value="{!listProducts}" var="Prod">
    <apex:column value="{!Prod.Provisioning_Status__c}" />
    <apex:column value="{!Prod.LastModifiedDate}"/>
    <apex:column value="{!Prod.Advertiser_Account__r.FRC_Site_ID__c}"/>
    <apex:column value="{!Prod.ProductCode}"/>
    <apex:column value="{!Prod.PricebookEntry.Product2.Name}"/>
    <apex:column value="{!Prod.Advertiser_Account__c}"/>
    <apex:column value="{!Prod.id}"/>

    <apex:column headerValue="Click to add info">
    <apex:commandButton value="Enter Data" onclick="doUnlink();">
       <apex:param id="oppProdId" value="{!Prod.Id}" assignTo="{!oppprorec}" />
    </apex:commandButton>
    </apex:column>


  
    
</apex:pageBlockTable>
</apex:pageBlock> 
</apex:pageBlock> 
</apex:form>
</apex:page>
---------------------------------------------------------------------------------------------------------------------------------
Here is the Controller (OppProductActivation)
Controller to display all the Opportunity Line Item Products


public with sharing class OppProductActivation {
public final Opportunity opp {get; set;}
public static List<OpportunityLineItem> listProducts {get;set;} 
    public OppProductActivation(ApexPages.StandardController controller) {
    this.opp = (Opportunity)controller.getRecord();
  }
public void FetchData() {
ListProducts = [Select Id, Provisioning_Status__c, ProductCode, Discounted_Rate__c, PricebookEntry.Product2.Name, Advertiser_Account__r.Name,  Advertiser_Account__r.FRC_Site_ID__c ,LastModifiedDate from OpportunityLineItem Where OpportunityId = :opp.Id and PricebookEntry.Product2.Product_Activation__c  = true  ];
}
}

----------------------------------------------------------------------------------------------------------------------------------
Here is the Controller (OppProductRecordActivation)
Controller to call the Visual Force Page 2
public class OppProductRecordActivation {
public final OpportunityLineItem oppprorec {get; set;}
    public OppProductRecordActivation(ApexPages.StandardController controller) {
   // this.oppprorec = (OpportunityLineItem)controller.getRecord();
}

public pageReference openPage() 
    {

        system.debug ('000000000 ' + oppprorec );
        pageReference pg = new pageReference('/apex/OppProductRecordActivationVF'+'?id='+oppprorec);
        pg.setRedirect(true);
        return pg;
    }       
}

-------------------------------------------------------------------
Visual Force Page 2 (OppProductRecordActivationVF)
<apex:page standardController="OpportunityLineItem" sidebar="false" language="en-US" > <apex:form id="form"> <apex:outputPanel id="tstid"> <apex:pageMessages /> </apex:outputPanel> <apex:outputLabel value="Product: " style="font-size:10px; "/> <apex:outputLabel value="{!OpportunityLineItem.PricebookEntry.Product2.Name}" style="font-weight:bold; font-size:20px; " /> </apex:form> </apex:page>
 
RICARDO PALMARICARDO PALMA
On OppProductRecordActivation I'm not able to get the Prod.Id passed into oppprorec, for that reason I'm getting an error creating or calling the VisualForce page, because the id is null.
V V Satyanarayana MaddipatiV V Satyanarayana Maddipati
Hi Ricardo,

I suggest you  remove the final keyword for the variable and change the data type as shown below :

public string oppprorec {get; set;}

You can call action method diretly in the commandButton as shown below .
 <apex:commandButton value="Enter Data" action="{!openPage}" rerender="refresh">
       <apex:param id="oppProdId" value="{!Prod.Id}" assignTo="{!oppprorec}" />
    </apex:commandButton>​


Hope this should resolve the issue.

Thanks
Satya.
RICARDO PALMARICARDO PALMA
Hi Satya thanks for your help,
I just added your suggestion but it didn't work. Now when click Enter Data is not doing anything, stay on the same page.
Thanks. 
YogeshMoreYogeshMore
Hello Ricardo,

Past following VF code to your existing code.
<apex:page standardController="Opportunity"  sidebar="true" action="{!FetchData}" extensions="OppProductActivation" language="en-US" >

<apex:form id="form">
<apex:outputPanel id="tstid">
<apex:pageMessages />
</apex:outputPanel>

<apex:outputLabel value="Opportunity: "  style="font-size:10px; "/>
<apex:outputLabel value="{!Opportunity.Name }" style="font-weight:bold; font-size:20px; " />

<apex:pageBlock >
        <apex:pageBlockButtons >
        <apex:commandButton value="Return to Opportunity" action="{!cancel}"/> 
        </apex:pageBlockButtons> 
<apex:pageBlock title="Products">

<apex:pageBlockTable value="{!listProducts}" var="Prod">  
    <apex:column value="{!Prod.LastModifiedDate}"/>
    <apex:column value="{!Prod.ProductCode}"/>
    <apex:column value="{!Prod.id}"/>
    <apex:column headerValue="Click to add info">
    <apex:commandButton value="Enter Data" onclick="window.open('/apex/OppProductRecordActivationVF?id={!Prod.id}','_self');" reRender="form">
       
    </apex:commandButton>
    </apex:column>

  
    
</apex:pageBlockTable>
</apex:pageBlock> 
</apex:pageBlock> 
</apex:form>
</apex:page>

and there is no need of second controller name as "OppProductRecordActivation", you can delete that one. 
​If you go solution of your problem, then please mark this as best answer.


Regards,
YogRaj
This was selected as the best answer
RICARDO PALMARICARDO PALMA
Thanks to both of you.
YogRaj it works!!!!
Thank you so much again.