0

I need to get the contact details when i click on name column. The name column contains the contact when i click on them i need its details.

Can anybody help!!

Visualforce page

   <apex:page controller="AccountContactController">
    <apex:form >
        <apex:pageBlock title="Account Name">
            <apex:actionFunction name="change" action="{!refreshContactList}" reRender="pbt" />            
            <apex:selectList value="{!selectedAccId}" size="1" onchange="change()" title="Accounts">
            <apex:selectOptions value="{!AccountNames}" />
            </apex:selectList><br/><br/>
            <b>Related Contacts</b>          
            <apex:pageblockTable title="Contacts" value="{!Conlist}" var="Sc" id="pbt">     
            <apex:inlineEditSupport showOnEdit="save" hideOnEdit="edit"/>                 
                <apex:column value="{!Sc.name}"/> 
                <apex:column value="{!Sc.phone}"/>                       
            <apex:commandLink value="{!Sc.name}"/>
            <apex:pageblockSection >
                <apex:actionSupport action="{!refreshContactDetails}" event="onclick" rerender="detail" status="mystatus">
                    <apex:param name="cid" assignTo="{!selectedConId}" value="{!Sc.id}"/>
                     <apex:detail id="detail" relatedList="true" subject="{!Sc.id}"/>
                </apex:actionSupport>
               </apex:pageblockSection>
        </apex:pageblockTable> 
           <center> <apex:commandButton value="Edit"  id="edit"/></center>&nbsp;
           <center><apex:commandButton value="Save" id="save" action="{!Save}"/></center>      
        </apex:pageBlock>  
    </apex:form>
    </apex:page>

Controller

Public with sharing class AccountContactController {   
    Public Id selectedAccId{get;set;} 
    public integer phone{get;set;}
    Public List<Contact> SelectedContacts{get;set;}
    Public List<Contact> Conlist{get;set;}    
    Public List<SelectOption> getAccountNames() {
        List<SelectOption> accOptions= new List<SelectOption>();
        system.debug(selectedAccId);
        accOptions.add( new SelectOption('','--Select--'));
        for(Account acc : [select Id,name from Account ] ) {
            accOptions.add(new SelectOption(acc.Id,acc.name));
        }
        return accOptions;
    }
      public List<Contact> SelectedContacts(){
         return Conlist;
      }
    public void refreshContactList(){
        Conlist = new List<Contact>();
        Conlist = [select name,phone from Contact where Accountid=: selectedAccId];
    }
   Public PageReference Save() {
        update Conlist;
        return null;
    }

}

2 Answers 2

0

Hi Deepak I think this is what you are looking for

Controller

    Public with sharing class AccountContactController {   
    Public Id selectedAccId{get;set;} 
    public integer phone{get;set;}
    Public List<Contact> SelectedContacts{get;set;}
    Public List<Contact> Conlist{get;set;} 
    Public List<SelectOption> getAccountNames() {
        List<SelectOption> accOptions= new List<SelectOption>();
        system.debug(selectedAccId);
        accOptions.add( new SelectOption('','--Select--'));
        for(Account acc : [select Id,name from Account ] ) {
            accOptions.add(new SelectOption(acc.Id,acc.name));
        }
        return accOptions;
    }
      public List<Contact> SelectedContacts(){
         return Conlist;
      }
    public void refreshContactList(){
        Conlist = new List<Contact>();
        Conlist = [select name,phone from Contact where Accountid=: selectedAccId];
    }
   Public PageReference Save() {
        update Conlist;
        return null;
    }
}

VisualForce

    <apex:page controller="AccountContactController">
<apex:form >
    <apex:pageBlock title="Account Name">
        <apex:actionFunction name="change" action="{!refreshContactList}" reRender="pbt" />            
        <apex:selectList value="{!selectedAccId}" size="1" onchange="change()" title="Accounts">
        <apex:selectOptions value="{!AccountNames}" />
        </apex:selectList><br/><br/>
        <b>Related Contacts</b>   
        <apex:detail id="detail" rerender="Click"/>
        <apex:pageblockTable title="Contacts" value="{!Conlist}" var="Sc" id="pbt">
        <apex:inlineEditSupport showOnEdit="save" hideOnEdit="edit"/>     
        <apex:column>
            <apex:outputLink value="/{!Sc.Id}">{!Sc.name}</apex:outputLink>
        </apex:column>        
        <apex:column value="{!Sc.phone}"/>
        </apex:pageblockTable>   
        <center> <apex:commandButton value="Edit"  id="edit"/></center>&nbsp;
       <center><apex:commandButton value="Save" id="save" action="{!Save}"/></center>      
    </apex:pageBlock>  
</apex:form>
</apex:page>

If it solves your problem mark it as answer. Thanks!!

3
  • If you need any explanation, you can ask any time...feel free to ask
    – Saran Dev
    Dec 9, 2016 at 14:48
  • HI Saran, thanks for your reply..But the thing is after i click the link i am not getting details Dec 9, 2016 at 14:55
  • It is working perfectly and I have tested it. What's the problem you are facing please share
    – Saran Dev
    Dec 12, 2016 at 6:55
0

Use apex:actionSupport on apex:column to capture the click event on table row. Pass the contact Id back to Controller with the help of apex:param. Now you can fetch the details in refreshContactDetails() and pass it back to the vf page to render the contact details.

Vf Page

.........
.........
    <apex:pageblockTable title="Contacts" value="{!Conlist}" var="Sc" id="pbt">
        <apex:inlineEditSupport showOnEdit="save" hideOnEdit="edit"/>     
        <apex:column>
            <apex:actionSupport action="{!refreshContactDetails}" event="onclick" rerender="detail" status="mystatus">
                <apex:param name="cid" assignTo="{!selectedConId}" value="{!Sc.id}"/>
            </apex:actionSupport>
            <apex:outputText value="{!Sc.name}"/>                    
        </apex:column>        
        <apex:column value="{!Sc.phone}"/>
    </apex:pageblockTable>
.......
.......

Controller

..........
..........
Public Id selectedConId{get;set;} 
..........
..........
Public PageReference refreshContactDetails() {
    System.debug('Selected Contact : '+selectedConId);
    return null;
}
..........
..........

Update

To get the contact link as hyperlink use <apex:outputLink replace the line

<apex:outputText value="{!Sc.name}"/> with the below line

<apex:outputLink onclick="return false;" >{!Sc.name}</apex:outputLink>
2
  • Thanks Saroj for your reply..its working but i am not getting any link on contact name Dec 9, 2016 at 14:37
  • Check my update. If this answer has solved your question you can use the check mark next to it to mark it as such. That will help others who are looking at it to locate the accepted solution.
    – Saroj Bera
    Dec 9, 2016 at 18:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .