1

I have an Account list in my visualforce page, when I click the name of the account, the details of the particular clicked account should be displayed in another section below in the same visualforce page.

I have used tag for the names of Account and I want the Id of the particular clicked Account name. How can I get it?

<apex:page standardController="Account" extensions="AccListDetailsController"  recordSetVar="accts">
<apex:form >

<apex:pageBlock title="List of Accounts" mode="edit">
 <apex:pageBlockSection columns="1">
      <apex:pageblockTable value="{!accts}" var="a">

      <apex:column headerValue="Name">
    <!--   <apex:outputLink value="/{!a.id}">{!a.name}</apex:outputLink> -->
      <apex:commandLink value="{!a.name}" action="{!getDetails}"/> 
      <apex:param name="{!a.id}" value="{!a.id}" assignTo="{!accountId}"/> 

      <apex:actionSupport event="onclick" action="{!getDetails}"  reRender="counterStatus"/> 
      </apex:column>
      <apex:column value="{!a.Phone}"/>
      <apex:column value="{!a.Phone}" /> 
      <apex:column value="{!a.Fax}"/>
  </apex:pageblockTable>
  </apex:pageBlockSection>

  <apex:pageBlockSection columns="1" id="targ" title="Details of Account Clicked">
    <apex:pageBlockTable value="{!accts}" var="v">
      <apex:column value="{!v.name}"/>
      <apex:column value="{!v.Email__c}"/>
    </apex:pageBlockTable>      

  <apex:actionStatus id="counterStatus"/>
  </apex:pageBlockSection>

public class AccListDetailsController{

 public String accountId{get;set;}

  public AccListDetailsController(ApexPages.StandardSetController controller) {

      }

  public PageReference getDetails(){
    System.Debug('The value in accId id :'+ accountId);
    List<Account> acList=[select name,email__c,id from Account where Id=:accountId];

    return null;
}
}
1
  • I think it would be easier to help you if you post some code. But basic idea is to make some wrapper class, an make action on command link on that wrapper class, which would fire for particular account, and display it where needed
    – kurunve
    Apr 13 '16 at 7:49
1

You can pass the Id from VF page to controller using <apex:param>

<apex:commandLink value="{!iterationvariable.Name}" rerender="">
    <apex:param assignTo="{!your variable in controller}" name="{!iterationvariable.Id}" value="{!iterationvariable.Id}"/>
<apex:commandLink>

and in controller you can use this Id and make processing like querying specific account and displaying it in separate section.

Edit:

After going through your updated question with code, you queried the account with the id passed and assigned it to accts variable which will change the values in the table as well.

So create a Account variable and assign the result of query to it and display it in the separate section.

public Account acc {get; set;}

In getDetails method, assign the query to this Account variable.

public PageReference getDetails(){
    System.Debug('The value in accId id :'+ accountId);
    acc = [select name,email__c,id from Account where Id=:accountId];
    return null;
}

Change the VF page to use this Account variable.

<apex:pageBlockTable value="{!acc}" var="v" id="details">
  <apex:column value="{!v.name}"/>
  <apex:column value="{!v.Email__c}"/>
</apex:pageBlockTable>

For <apex:actionSupport> to work, you need to pass a id of a component to rerender. So i have given the <apex:pageBlockTable> a id named details. Use <apex:actionSupport event="onclick" action="{!getDetails}" reRender="details"/>

Hope it helps.

3
  • I have updated my answer with some suggestions. Please take a look. Apr 13 '16 at 12:04
  • It worked!!! @Vigneshwaran Apr 13 '16 at 14:06
  • If the provided solution worked for you, upvote and accept the answer so that others with same issue gets benefited. Thanks. Apr 13 '16 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.