Skip to main content
pooja biswas preguntó en #Apex
Hi

I need to capture the ID of selected record from vf page into the controller's command button for further processing.

I am not figuring out how to capture the ID of selected record.

pls help me out.

Here is the code

 

public class MyAccountIDExt

{

List<Account> accts=[select ID,Name from Account Order By Name];

public string SelectedAccountId{get;set;}

private Account acc;

public MyAccountIDExt(ApexPages.StandardController stdcontroller)

{

this.acc=(Account)stdcontroller.getRecord();

}

public list<Account> getshowAccounts()

{

return accts;

}

public void GetId()

{

//I need the ID of the selected record which I select in visual force page

}

}

<apex:page standardController="Account"

extensions="MyAccountIDExt">

<apex:form>

<apex:pageBlock>

<apex:pageBlockTable value="{!showAccounts}"

var="a">

<apex:column value="{!a.Name}"/>

<apex:commandLink value="{!a.Name}">

<apex:param name="SelectedAccountId"

value="{!a.Id}"

assignTo="{!SelectedAccountId}"/>

</apex:commandLink>

</apex:pageBlockTable>

</apex:pageBlock>

<apex:commandButton action="{!GetID}"

value="Get ID"/>

</apex:form>

</apex:page>

Thanks

pooja

 
3 respuestas
  1. 18 ago 2016, 11:10
    Hi balaji

    Thanks for ur reply but I dont think it works that way.

    I made small modificaiton to the vf page as shown in bold and as u said correctly <apex:commandbutton> is not required.

    <apex:column value="{!a.Name}"/>

          <apex:column width="12%">

                     <apex:commandLink action="{!GetId}">

                                      

                            <apex:param name="SelectedAccountId"

                                        value="{!a.Id}"

                                        assignTo="{!SelectedAccountId}"/>

                                       

                                     <h1> FetchID</h1>

                        </apex:commandLink>

             </apex:column>

    The controller code remains the same.

    Now when I check debug logs, I can see the recordID of the account I selected.

    Thanks

    pooja

     
0/9000