You need to sign in to do that
Don't have an account?

How to pass the id from visualforce page when i click the preview button
When i click on the preview button the id of the associated record id should get passed to the controller. Its urgent
You need to sign in to do that
Don't have an account?
Also put System.debug to print selectedid in controller before you assing value into it from request parameter.
All Answers
<apex:pageBlockTable value="{!feed}" var="a" rowClasses="oddrow,evenrow,dataTableRow" styleClass="fontfamily" id="Details1" style="width:50%;"> <apex:column headerValue="Feedback Preview" style="width:35%;" > <apex:inputHidden value="{!a.id}" id="theField" /> <script> var theField = document.getElementById('{!$Component.theField}'); </script> </apex:column> <apex:column headerValue="Feedback Number" style="width:10%;"> <apex:outputField value="{!a.Name}" id="test" /> <apex:param name="Selectedid" value="{!a.Name}"/> <apex:variable var="vara" value="{!a.Name}" /> </apex:column> <apex:column headerValue="Feedback Preview" style="width:45%;" > <apex:commandButton action="{!queslist}" onclick="theField.value=v;" value="Preview" style="width:35%;" /> </apex:column> </apex:pageBlockTable>
public class FeedbackMainlistController { Public Id qid{get;set;} public string Selectedid {get;set;} public List <FeedbackMain__c>queslist; public List<FeedbackMain__c> showQues; public List<FeedbackMain__c> feed; public List<Feedback_Question_Main__c> question; public FeedbackMainlistController(ApexPages.StandardController controller) { selectedid= System.currentPageReference().getParameters().get('Selectedid '); system.debug('*********Selected id is:*******************'+selectedid); qid=controller.getId(); //system.debug('*********Selected id is:*******************'+qid); //system.debug('*********Selected id is:*******************'+Selectedid); } public List<FeedbackMain__c> getFeed() { feed=[SELECT id,name,Feedback_Name__c,Related_Question_Bank__r.name FROM FeedbackMain__c]; return feed; } public List<Feedback_Question_Main__c> getQuestion() { question=[SELECT name,Related_Feedback__c,Option_Five__c,Option_Four__c,Option_One__c,Option_Three__c,Option_Two__c,Question__c FROM Feedback_Question_Main__c where Related_Feedback__c='a0036000003zDGR']; return question; } public pageReference queslist() { selectedid= System.currentPageReference().getParameters().get('Selectedid'); showQues=[SELECT Related_Question_Bank__r.Name FROM FeedbackMain__c where id=:'a0036000003zDGR']; system.debug('*********Selected id is:*******************'+Selectedid); PageReference pageRef = new PageReference('/apex/FeedbackQuestionMain'); pageRef.setRedirect(true); return pageRef ; } }
#1. Using apex Actionsupport tag like below
#2. Using action function and on button click call that JS function which in return will call action by passing parameter that you passed to js function
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_actionFunction.htm (Use this along with apex:param to pass parameter)
Let me know if that help, i might get some example if case you need.
Thanks!
<apex:column headerValue="Feedback Preview" style="width:45%;" >
<apex:commandButton value="Preview" style="width:35%;" >
<apex:actionSupport action="{!queslist}" event="onclick" >
<apex:param assignTo="{!selectedId}" value="{!a.id}" name="selectedI"/>
</apex:actionsupport>
</apex:commandButton>
</apex:column>
Used the following code.still its not working
<apex:page standardController="FeedbackMain__c" extensions="FeedbackMainlistController">
<apex:form >
<apex:pageBlock >
<Script>
variable v=
</script>
<apex:pageBlockTable value="{!feed}" var="a" rowClasses="oddrow,evenrow,dataTableRow" styleClass="fontfamily" id="Details1" style="width:50%;">
<apex:column width="1%" >
<apex:inputHidden value="{!a.id}" id="theField" />
<apex:param name="Selectedid" value="{!a.id}"/>
<script> var theField = document.getElementById('{!$Component.theField}'); </script>
</apex:column>
<apex:column headerValue="Feedback Number" style="width:10%;">
<apex:outputField value="{!a.Name}" id="test" />
<apex:param name="Selectedid" value="{!a.Name}"/>
<apex:variable var="vara" value="{!a.Name}" />
</apex:column>
<apex:column headerValue="Feedback Preview" style="width:45%;" >
<apex:commandButton value="Preview" style="width:35%;" >
<apex:actionSupport action="{!queslist}" event="onclick" >
<apex:param assignTo="{!selectedId}" value="{!a.id}" name="selectedI"/>
</apex:actionsupport>
</apex:commandButton>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
public class FeedbackMainlistController
{
Public Id qid{get;set;}
public string Selectedid {get;set;}
public List <FeedbackMain__c>queslist;
public List<FeedbackMain__c> showQues;
public List<FeedbackMain__c> feed;
public List<Feedback_Question_Main__c> question;
public FeedbackMainlistController(ApexPages.StandardController controller)
{
selectedid= System.currentPageReference().getParameters().get('Selectedid ');
system.debug('*********Selected id is:*******************'+selectedid);
qid=controller.getId();
//system.debug('*********Selected id is:*******************'+qid);
//system.debug('*********Selected id is:*******************'+Selectedid);
}
public List<FeedbackMain__c> getFeed()
{
feed=[SELECT id,name,Feedback_Name__c,Related_Question_Bank__r.name FROM FeedbackMain__c];
return feed;
}
public List<Feedback_Question_Main__c> getQuestion()
{
question=[SELECT name,Related_Feedback__c,Option_Five__c,Option_Four__c,Option_One__c,Option_Three__c,Option_Two__c,Question__c FROM Feedback_Question_Main__c where Related_Feedback__c='a0036000003zDGR'];
return question;
}
public pageReference queslist()
{
selectedid= System.currentPageReference().getParameters().get('Selectedid');
showQues=[SELECT Related_Question_Bank__r.Name FROM FeedbackMain__c where id=:'a0036000003zDGR'];
system.debug('*********Selected id is:*******************'+Selectedid);
PageReference pageRef = new PageReference('/apex/FeedbackQuestionMain');
pageRef.setRedirect(true);
return pageRef ;
}
}
Can you please post the solution again
It looks good. Could you make following 2 changes.
- Add <apex:pageMessages /> at very first statement of <apex:pageBlock > and give id to pageblock and add rerender= pageblock id to apex:actionSupport stement
- get parameter has capital s for selectedid so fix it also put sop before you populate it from request parameter because salesforce automatically set value from fields and you may not additionally need to do that.
Thanks!showQues=[SELECT Related_Question_Bank__r.Name FROM FeedbackMain__c where id=:'a0036000003zDGR'];
I want the id to be dynamic that is why i want the associated id on button click in the controller..
But in the controller i am getting the id as null.
Can you please post the corrected code as i am not able to figure out the exact way that you have suggested
Also put System.debug to print selectedid in controller before you assing value into it from request parameter.
I was able to get the id in the queslist() successfully .However when i try to get the id in getQuestion() the debug log is showing it as null.
Not able to get why this is happening.
public class FeedbackMainlistController
{
Public Id qid{get;set;}
public string Selectedid {get;set;}
String idfetch;
public List <FeedbackMain__c>queslist;
public List<FeedbackMain__c> showQues;
public List<FeedbackMain__c> feed;
public List<Feedback_Question_Main__c> question;
public FeedbackMainlistController(ApexPages.StandardController controller)
{
selectedid= System.currentPageReference().getParameters().get('Selectedid');
}
public List<FeedbackMain__c> getFeed()
{
feed=[SELECT id,name,Feedback_Name__c,Related_Question_Bank__r.name FROM FeedbackMain__c];
return feed;
}
public pageReference queslist()
{
//selectedid= System.currentPageReference().getParameters().get('Selectedid');
showQues=[SELECT Related_Question_Bank__r.Name FROM FeedbackMain__c where id=:Selectedid];
system.debug('*********Selected id is in ques list :*******************'+Selectedid);
idfetch=Selectedid;
system.debug('*********Selected id fetched :*******************'+idfetch);
PageReference pageRef = new PageReference('/apex/FeedbackQuestionMain');
// PageReference pageRef = new PageReference('/apex/FeedbackQuestionMain?param='+Selectedid);
pageRef.setRedirect(false);
return pageRef ;
}
public List<Feedback_Question_Main__c> getQuestion()
{
system.debug('*********Selected id fetched :*******************'+idfetch);
question=[SELECT name,Related_Feedback__c,Option_Five__c,Option_Four__c,Option_One__c,Option_Three__c,Option_Two__c,Question__c FROM Feedback_Question_Main__c where Related_Feedback__c=:Selectedid];
system.debug('**************************************'+question);
return question;
}
}