• vijay333551.3966074804040708E12
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Hi All,

I am get getting list of accounts as command links in visual force page once i click a particualr account releated contact details record names are 

displayed as command links again if i click on particular contact i need to redirect  contact record detail page instead of it i am redirecting to home

page i guess i am getting home page ID instead of Contact ID  and help me how to get record ID on CommandLink Click 

<apex:page controller="MyController">
    <apex:form >
     <apex:pageBlock title="Accounts Info">
     <apex:pageBlockSection title="Accouns">
     <apex:dataList value="{!myaccounts}" var="acct">
       <apex:commandlink action="{! accountClicked}" rerender="ContactDetail">
    <apex:outputText value="{! acct.name}"/>
    <apex:param name="id" value="{! acct.Id}" assignTo="{!selectedAccount}"/>
    </apex:commandLink>
     </apex:dataList>
    </apex:pageBlockSection>
   
    <apex:pageBlockSection title="Contact Records">
   
    <apex:outputPanel id="ContactDetail">
    <apex:repeat value="{! contactsInformation}" var="contact">
     <p><apex:commandLink action="{!contactClicked}">
      <apex:outputText value="{! contact.Name}"/>
     <apex:param name="id1" value="{!contact.id}" assignTo="{!selectedContact}"/>
     </apex:commandLink></p>
    </apex:repeat>
   
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

---contrlooer code---

public class MyController {

  
    public Id selectedAccount { get; set; } 
    public List<Contact> contactsInformation { get; set; }
    public Id selectedContact { get; set; } 
  
    public PageReference contactClicked() {
   
    List<Contact> id = [select id from contact where id =:selectedContact];
     
      PageReference nextpage = new PageReference('https://na15.salesforce.com/?id='+id);
                return nextpage;
    }


   



    public List<Account> getMyaccounts() {
       
        return [SELECT Id, Name, AccountNumber FROM Account ORDER BY
           LastModifiedDate DESC LIMIT 10];
    }


    public void accountClicked() {
    contactsInformation = [SELECT Name,id FROM Contact
            WHERE AccountID = :selectedAccount];
}




}