function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Patrick ConnerPatrick Conner 

Linked Results on Custom VisualForce Page

Hey!

I'm having some trouble displaying linked results on a VisualForce page; I don't seem to have the best grasp on the outputlink function. What I'd like is for results to be displayed as below, but for the Name to link to the individual contact. Any idea how I can do this? Please let me know if you need more info, and thanks for the help!

Here's what I have for the pageBlockTable:

<apex:pageBlockTable value="{!contacts}" var="contact">

            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Name" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="Name" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputLink value="/!{Contact.id}">{!Contact.Name}</apex:outputLink>
            </apex:column>

            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Email" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="Email" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!contact.Email}"/>
            </apex:column>

            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Phone" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="Phone" value="Phone.name" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!contact.Phone}"/>
            </apex:column>

          

        </apex:pageBlockTable>
Best Answer chosen by Patrick Conner
James LoghryJames Loghry
Looks like you're close, you're just one character off.

Chang this line:

<apex:outputLink value="/!{Contact.id}">{!Contact.Name}</apex:outputLink>

To:

<apex:outputLink value="/{!Contact.id}">{!Contact.Name}</apex:outputLink>

(Note how I swapped the exclamation mark on the curly brace around)

Another way you could do this would be using the URLFOR, which is in my opinion safer to use:

<apex:outputLink value="{!URLFOR($Action.Contact.view,Contact.id)}">{!Contact.Name}</apex:outputLink>

Here are a couple links on URLFOR and other Visualforce functions:
https://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_functions.htm
http://salesforcesource.blogspot.com/2008/12/urlfor-function-finally-explained.html


All Answers

James LoghryJames Loghry
Looks like you're close, you're just one character off.

Chang this line:

<apex:outputLink value="/!{Contact.id}">{!Contact.Name}</apex:outputLink>

To:

<apex:outputLink value="/{!Contact.id}">{!Contact.Name}</apex:outputLink>

(Note how I swapped the exclamation mark on the curly brace around)

Another way you could do this would be using the URLFOR, which is in my opinion safer to use:

<apex:outputLink value="{!URLFOR($Action.Contact.view,Contact.id)}">{!Contact.Name}</apex:outputLink>

Here are a couple links on URLFOR and other Visualforce functions:
https://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_functions.htm
http://salesforcesource.blogspot.com/2008/12/urlfor-function-finally-explained.html


This was selected as the best answer
Patrick ConnerPatrick Conner
Wow I feel dumb. Thank you so much!
Jim JamJim Jam
try moving the ! character inside the curly bracket for the outputLink ... ie ..

<apex:outputLink value="/{!Contact.id}">{!Contact.Name}</apex:outputLink>