You need to sign in to do that
Don't have an account?
How to Get Id in Apex from Vf page
Here is my code .....i didnot pass id value from pageblocktable column (param tag) to apex class ... it gives null....value...so please help me...
<apex:page controller="approvalclass" sidebar="false">
<apex:form >
<apex:pageBlock >
<apex:pageblockTable value="{!data}" var="d">
<apex:column >
<apex:outputPanel >
<apex:commandButton action="{!approvalagent}" value="Approv">
<apex:param value="{!d.id}" name="{!passid}" assignTo="{!passid}"/>
</apex:commandButton>
<apex:commandButton action="{!rejectagent}" value="Regect">
<apex:param value="{!d.id}" assignTo="{!passid}" name="passid"/>
</apex:commandButton>
</apex:outputPanel>
</apex:column>
<apex:column value="{!d.Account__c}"/>
<apex:column value="{!d.State_Territory__c}"/>
<apex:column value="{!d.Policy_Types__c}"/>
<apex:column value="{!d.Policie_status__c}"/>
<apex:column value="{!d.State_Territory__c}"/>
<apex:column value="{!d.Commission_Rate__c}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
-------------------------
class
public with sharing class approvalclass {
public string passid { get; set; }
public list<policie__c> p=new list<policie__c>();
list<policie__c> pc=new list<policie__c>();
public approvalclass(){
passid= System.currentPageReference().getParameters().get('id');
system.debug('*********************************************'+passid); }
public PageReference rejectagent() {
system.debug('*********************************************'+passid);
pc=[select id,name,Maturity_Amount__c,Commission_Rate__c,Account__c,Policie_status__c,Policy_Types__c,Premium_Amount__c,State_Territory__c from policie__c];
for(policie__c pt:pc )
{
if(pt.Commission_Rate__c!=null && pt.id==passid)
pt.Approval_status__c='Reject';
upsert pt;
}
return null;
}
public PageReference approvalagent() {
system.debug('*********************************************'+passid);
pc=[select id,name,Maturity_Amount__c,Commission_Rate__c,Account__c,Policie_status__c,Policy_Types__c,Premium_Amount__c,State_Territory__c from policie__c];
for(policie__c pts:pc)
{
if(pts.Commission_Rate__c!=null && pts.id==passid)
pts.Approval_status__c='approval';
upsert pts;
}
pagereference ref = new pagereference('https://ap1.salesforce.com'+passid);
ref.setredirect(true);
return ref;
}
public list<policie__c>getData() {
p=[select id,name,Maturity_Amount__c,Account__c,Policie_status__c,Policy_Types__c,Premium_Amount__c,Commission_Rate__c,State_Territory__c from policie__c where ownerid=:userinfo.getuserid()];
return p;
}
}
Hi,
it is advisable to use an actionFunction outside of iterative markup like <apex:repeat> and <apex:pageBlockTable>. This means you have one javascript function and the same one is called and the parameter passed in. The actionFunctin should be outside of the <apex:pageBlockTable>. Also, you need to specify an element to reRender or the assignTo will not work. Try the below;
<apex:page controller="approvalclass" sidebar="false">
<apex:form >
<apex:actionFunction name="approv" action="{!approvalagent}" reRender="pageBlock">
<apex:param name="dataId" assignTo="{!passid}" value="">
</apex:actionFunction>
<apex:actionFunction name="regect" action="{!rejectagent}}" reRender="pageBlock">
<apex:param name="dataId" assignTo="{!passid}" value="">
</apex:actionFunction>
<apex:pageBlock id="pageBlock" >
<apex:pageblockTable value="{!data}" var="d">
<apex:column >
<apex:outputPanel >
<apex:commandButton onclick="approv('{!d.id}');" value="Approv"/>
<apex:commandButton onclick="regect('{!d.id}');" value="Regect"/>
</apex:outputPanel>
</apex:column>
<apex:column value="{!d.Account__c}"/>
<apex:column value="{!d.State_Territory__c}"/>
<apex:column value="{!d.Policy_Types__c}"/>
<apex:column value="{!d.Policie_status__c}"/>
<apex:column value="{!d.State_Territory__c}"/>
<apex:column value="{!d.Commission_Rate__c}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Thanks,
James.
Hi,
You can refer the blog from Jeff Douglas. When we use <apex:param> with <apex:commandButton>, you need to rerender something to get the param value from VF to apex class.
Hope this helps :)
I am sorry to say .....This process does not give right expected value...It means it doesn't return any value .It returns only ..Null
Apologies, you need a reRender on the commandButton too, but a hidden outputPanel will do here.
<apex:page controller="approvalclass" sidebar="false">
<apex:form >
<apex:actionFunction name="approv" action="{!approvalagent}" reRender="pageBlock">
<apex:param name="dataId" assignTo="{!passid}" value="">
</apex:actionFunction>
<apex:actionFunction name="regect" action="{!rejectagent}" reRender="pageBlock">
<apex:param name="dataId" assignTo="{!passid}" value="">
</apex:actionFunction>
<apex:pageBlock id="pageBlock" >
<apex:pageblockTable value="{!data}" var="d">
<apex:column >
<apex:outputPanel >
<apex:commandButton onclick="approv('{!d.id}');" value="Approv" reRender="hiddenPanel"/>
<apex:commandButton onclick="regect('{!d.id}');" value="Regect" reRender="hiddenPanel"/>
</apex:outputPanel>
</apex:column>
<apex:column value="{!d.Account__c}"/>
<apex:column value="{!d.State_Territory__c}"/>
<apex:column value="{!d.Policy_Types__c}"/>
<apex:column value="{!d.Policie_status__c}"/>
<apex:column value="{!d.State_Territory__c}"/>
<apex:column value="{!d.Commission_Rate__c}"/>
</apex:pageblockTable>
</apex:pageBlock>
<apex:outputPanel id="hiddenPanel"/>
</apex:form>
</apex:page>
Your code looks good to me I guess a minor adjustment should fix the issue