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
SunnyButCloudySunnyButCloudy 

VF Page outputField function help

Hello,

 

I'm fairly new to VF development and am running into a small issue.  I have a custom object that has a lookup to an account and a lookup to a contact (+ other custom fields). 

 

I built a VF page to pull these fields and overall page is rendered as PDF.  The problem I have is that the account and contact fields both show up as links (and therefore underlined and in blue).  Is there a way I can just make them come out as normal text?  I tried using outputText function, but then the IDs come out, instead of the account and contact name.

 

Any help is highly appreciated.  Thank you x 100 in advance.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
jwetzlerjwetzler

Try using the name field on the parent object instead of the lookup field on your custom object.

 

For example, I have a custom object called "object" with lookup fields to account and opportunity called account__c and opportunity__c, respectively.  I can access the fields on those objects like this:

 

    <apex:outputField value="{!object__c.account__r.name}"/><br/>
    <apex:outputField value="{!object__c.opportunity__r.name}"/>

 

 

All Answers

jwetzlerjwetzler

Try using the name field on the parent object instead of the lookup field on your custom object.

 

For example, I have a custom object called "object" with lookup fields to account and opportunity called account__c and opportunity__c, respectively.  I can access the fields on those objects like this:

 

    <apex:outputField value="{!object__c.account__r.name}"/><br/>
    <apex:outputField value="{!object__c.opportunity__r.name}"/>

 

 

This was selected as the best answer
SunnyButCloudySunnyButCloudy

Oh perfect!! Thanks Jill.  Cheers

elpaso750_develpaso750_dev

Hi,

thanks for this post, I'd have a couple of questions :

 

does this work only for emails and/or pdf output ? or also for standard VF pages ?

 

would it work only for field NAME or also other fields ? (description, desk__c) I'm asking this 'cause I did try and came up with some strange errors.

 

what I'd like to achieve is, I think, pretty simple.

 

I have two custom objects (Software__c and Tests__c) and a third custom object (test2run__c) with lookup relation to the first two objects.

 

I just wish to have a VF page for test2run__c showing the fields of one single record of the (test2run__c) and some of the fields of the related 'parent' objects

 

I did try  

 

<apex:inputField value="{!Test2run__c.Compulsory__c}"/>
<apex:inputField value="{!Test2run__c.Assigne_to_User__c}"/>
<apex:inputField value="{!Test2run__c.Completed__c}"/>
<apex:inputField value="{!Test2run__c.Test_Comments__c}"/>

and the fields for the related objects :

 

<apex:outputText value="{!test2run.Software__r.Software_to_Be_Tested__c}"/>
<apex:outputText value="{!test2run.Software__r.Version__c}"/>

and 

<apex:outputField value="{!Test2run__c.Tests__r.Name}"/>
<apex:outputField value="{!Test2run__c.Tests__r.Description__c}"/>

 

 

but getting errors on the VF page

 

thanks for any help

 

Alex