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
Megan Moody 10Megan Moody 10 

Display label with apex:outputLink?

I have a simple pageblocksection in my VF page in which I went to display a contact's associated Account record and then a custom lookup field. The problem is that when I display the contact's associated account, it doesn't provide a hyperlink to the account as it does for my custom lookup field.

User-added image

I can get the Account to become a hyperlink by using the outputLink tag, but then I don't have a label next to it. 

User-added image

Is there anyway to display a label next to the linked Account Name such that it looks like the label "Health Plan" below it? 

 
Mudasir WaniMudasir Wani

Hey Megan,

Paste your code here.
It should display the account as lookup.
Are you using inputField or not ?

Thanks,
Mudasir

Megan Moody 10Megan Moody 10
Code for the top screen shot is:
<apex:PageBlockSection title="Employer & Health Plan" columns="1">
            <apex:outputField value="{!Contact.Account.Name}"/>
            <apex:outputField value="{!Contact.Health_Plan__c}"/>
 </apex:PageBlockSection>

Code for the bottom screen shot is:
 
<apex:PageBlockSection title="Employer & Health Plan" columns="1">
            <apex:outputLink value="/{!Contact.Account.id}">{!Contact.Account.Name}</apex:outputlink>
            <apex:outputField value="{!Contact.Health_Plan__c}"/>
</apex:PageBlockSection>
KaranrajKaranraj
Try with the below lines of code, hope that will works for you
<apex:PageBlockSection title="Employer & Health Plan" columns="1">
            Account Name : <a href="/{!Contact.Account.id}">{!Contact.Account.Name}</a>
            <apex:outputField value="{!Contact.Health_Plan__c}"/>
</apex:PageBlockSection>

 
Megan Moody 10Megan Moody 10
That works, but the link opens up in the VF page. I need it to open up in the Console. The URL when I'm in the console is always https://na11.salesforce.com/console, so I'm not sure I can pass the id to it. Thoughts? 

Thanks!
KaranrajKaranraj
Megan - You can do that by using java script in your visualsforce page. Try the below code
<apex:includeScript value="/support/console/29.0/integration.js"/>
    <script type="text/javascript">           
        function openSubTab(recId){
            var redirectUrl = recId;
            if (sforce.console.isInConsole()) {
                sforce.console.getEnclosingTabId(function(enclosingResult){
                    sforce.console.getEnclosingPrimaryTabId(function(primaryResult){
                        sforce.console.openSubtab(primaryResult.id, redirectUrl, true, '', null);
                    });
                });
            } else {
                // for inline Vf
                window.top.location.href = '/'+redirectUrl
                // for normal vf
                // window.location.href = '/'+redirectUrl
            }
        }        
    </script>

<apex:PageBlockSection title="Employer & Health Plan" columns="1">
  Account Name : <a href="#" onclick="openSubTab('{!Contact.Account.id}');">{!Contact.Account.Name}</a>
  <apex:outputField value="{!Contact.Health_Plan__c}"/>
</apex:PageBlockSection>