You need to sign in to do that
Don't have an account?
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????
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
commandlink may be overkill, what about this :
<apex:column headervalue="Account Name" width="500"> <a href="/{!ge.AccountId}">{!ge.Account.Name }</a> </apex:column>
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_.
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?
Perfect solution, worked for me,
Thanks
Neer