+ Start a Discussion
Krishna_Krishna_ 

VisualForcePage datatable with Command Link

Hi I am creating new Visual Force page that displays views of Contact.That view contains Contact Lastname & Contacts AccountName if Contact account name is there.

 

Its all ok.But i am used command link to that view. So If i click to contact Lastname that contact will be open & same for Account Name...

How to handle this one????

I am Hardcoded that value its working fine.But not hard coded itd not working...

 

My sample code is:

 

Apex Class::

 

public class dataTableCont 
{
    List<Contact> Con;
    public List<Contact> getContacts()
    {
        Con = [select id,LastName, AccountId,contact.Account.Name from contact where contact.AccountId != NULL];
        return Con;
    }
   
    public PageReference LinkContactName()
    {
      PageReference pdfPage =new PageReference('my org URL' + '/' + 'Contact.Id');
//If i am hardcoded the contact Id its working..
      pdfpage.setRedirect(true);
      return pdfPage;
    }
    public PageReference LinkAccountName()
    {
        PageReference pdfPage =new PageReference('my org URL' + '/' + Contact.AccountId);
        pdfpage.setRedirect(true);
        return pdfPage;
        //return null;
    }
}

My VisualForce Page::

 

<apex:page controller="dataTableCont" id="thePage">
<apex:form > 
   <apex:pageBlock title="Contacts">
   <apex:pageBlockTable value="{!Contacts}" var="ge">
                        <apex:column headervalue="Last Name" width="500">
                        <apex:commandLink action="{!LinkContactName}" value="{!ge.LastName}"  >
                             <apex:param name="ConLastName" value="{!ge.Id}"/>
                        </apex:commandLink>
                    </apex:column>
                   
                    <apex:column headervalue="Account Name" width="500">
                        <apex:commandLink action="{!LinkAccountName}" value="{!ge.Account.Name }" >
                             <apex:param name="ConAccName" value="{!ge.AccountId}"/>
                        </apex:commandLink>
                    </apex:column>
    </apex:pageBlockTable>
   </apex:pageBlock>
   </apex:form>
   </apex:page>

 

If i click to contact Lastname that contact will be open & same for Account Name.

How to handle this one????

Message Edited by Krishna_ on 05-12-2009 05:49 PM
Best Answer chosen by Admin (Salesforce Developers) 
Krishna_Krishna_

Thanks Ron Hess ,
Now its working Fine..

My sample code::

APEX CLASS::

 

public class dataTableCont
{
    List<Contact> Con;
    public List<Contact> getContacts()
    {
        Con = [select id,LastName, AccountId,contact.Account.Name from contact where contact.AccountId != NULL];
        return Con;
    }
}

 

VISUALFORCE PAGE::

 

<apex:page controller="dataTableCont" id="thePage">
<apex:form >
   <apex:pageBlock title="Contacts">
   <apex:pageBlockTable value="{!Contacts}" var="ge">
       <apex:column headervalue="Last Name" width="500">
           <a href="/{!ge.Id}">{!ge.LastName }</a>
       </apex:column>

       <apex:column headervalue="Account Name" width="500">
           <a href="/{!ge.AccountId}">{!ge.Account.Name }</a>
       </apex:column>

    </apex:pageBlockTable>
   </apex:pageBlock>
   </apex:form>
</apex:page>


Thanks,
Krishna_.

All Answers

Ron HessRon Hess

commandlink may be overkill, what about this :

 

 

<apex:column headervalue="Account Name" width="500"> <a href="/{!ge.AccountId}">{!ge.Account.Name }</a> </apex:column>

 

 i think it does what you are trying to do.

 

Krishna_Krishna_

Thanks Ron Hess ,
Now its working Fine..

My sample code::

APEX CLASS::

 

public class dataTableCont
{
    List<Contact> Con;
    public List<Contact> getContacts()
    {
        Con = [select id,LastName, AccountId,contact.Account.Name from contact where contact.AccountId != NULL];
        return Con;
    }
}

 

VISUALFORCE PAGE::

 

<apex:page controller="dataTableCont" id="thePage">
<apex:form >
   <apex:pageBlock title="Contacts">
   <apex:pageBlockTable value="{!Contacts}" var="ge">
       <apex:column headervalue="Last Name" width="500">
           <a href="/{!ge.Id}">{!ge.LastName }</a>
       </apex:column>

       <apex:column headervalue="Account Name" width="500">
           <a href="/{!ge.AccountId}">{!ge.Account.Name }</a>
       </apex:column>

    </apex:pageBlockTable>
   </apex:pageBlock>
   </apex:form>
</apex:page>


Thanks,
Krishna_.

This was selected as the best answer
Madhura BMadhura B

I am trying to implement a similar thing but on partner portal.

The code you have posted works fine but the landing tab appears on the column i have added on the home page but on the required tab.

how can i change it?

Neerpal singh 6Neerpal singh 6
@ron Hess

Perfect solution, worked for me,

Thanks
Neer