function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Abhishek Gupta 360Abhishek Gupta 360 

pass parameters(variable) dynamically from visual force page to custom controller method using button. <

CONTROLLER:
public class actual {
   ID myID {get;set;}
   public List<Account> getAccounts() {    
        List<Account> results = Database.query(
            'SELECT Id, Name,AccountNumber, AnnualRevenue,value__c FROM Account');
        return results;
   }
   public void opp(){
        Id IdOfMember = this.myID;
        System.debug(IdOfMember);
   }
}
VF PAGE:
<apex:page controller="actual" docType="html-5.0" extensions="actual">
    <apex:form >
    <apex:pageBlock >
    <apex:pageBlockTable value="{! accounts }" var="acc" >
        <apex:column >
            <apex:actionSupport action="{!opp}">
                  <apex:param assignTo="{!myID}" value="{!acc.ID}" />
               </apex:actionSupport>
            <apex:commandButton action="{!opp}" reRender="" value="create opp">
            </apex:commandButton>
        </apex:column>
        <apex:column value="{! acc.id }"/>
        <apex:column value="{! acc.AccountNumber }"/>
    </apex:pageBlockTable>
    </apex:pageBlock>
    </apex:form>
</apex:page>

clicking the add opportunity is error. system debugs' null. its sending ID as null from vf page always and not the id i link.
<apex:actionSupport> and <apex:param> are not linking dynamic parameters in table.
HELP!!!
Shivdeep KumarShivdeep Kumar
Hi Abhishek,

Please use the below VF page code to get the Id into Apex method--
 
<apex:pageBlock> <apex:pageBlockTable value="{!accounts}" var="acc"> <apex:column> <apex:commandButton value="Create Opp" action="{!opp}"> <apex:param name="accountIdToAssign" value="{!acc.Id}" assignTo="{!myID}"/> </apex:commandButton> </apex:column> <apex:column value="{!acc.Id}"/> <apex:column value="{!acc.AccountNumber}"/> </apex:pageBlockTable> </apex:pageBlock>


Please let me know if this help!

Thanks,
Shivdeep Kumar
Abhishek Gupta 360Abhishek Gupta 360

Thanks Shivdeep. 

I tried it and as usual its passing null parameter(id) back to controller from vf page
I.E. if I click on add opp for any account and it prints null.

its al
For moment I had made two buttons. one takes you to new url where id of account is passed in url and other button confirms add opp by taking the id from new url(add opp button is linked to new url at page level.)

My requirment was getting both things done in one button :(