
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
Hi balajiThanks 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.Thankspooja