+ Start a Discussion
src0010src0010 

Question about 'apex:outputText' & 'apex:outputField' value format

The following line:

 

 

Account: <apex:outputText value="{!X360_Contract_Cycle__c.Account__c}" />

 Produces the following on my VisualForce page (rendered as pdf):

 

 

Prepared for: 001Q0000008olvcIAA

 

I tried changing this to outputField instead of outputText (example below):

 

 

Account: <apex:outputField value="{!X360_Contract_Cycle__c.Account__c}" />

This displays the account name correctly (not the record ID).  That is good....except it included the account name as a selectable link on the rendered PDF.  What is the best way to output the value, not as the record ID, and not include the value as a link?  So far running into a little bit of a catch 22.  Thanks in advance for the help! 

 

Best Answer chosen by Admin (Salesforce Developers) 
ErikssonEriksson

Hi,

 

This is easy to display the account name but not a link using the outputText component.

try this:

 

Account: <apex:outputText value="{!X360_Contract_Cycle__c.Account__r.Name}" />

 You have to select the Account__r.Name from the object before using it.

 

Cheers

 

 

All Answers

Shailesh DeshpandeShailesh Deshpande

Outputfield:

 

A read-only display of a label and value for a field on a Salesforce object. An outputField component respects the attributes of the associated field, including how it should be displayed to the user. For example, if the specified outputField component is a currency field, the appropriate currency symbol is displayed. Likewise, if the outputField component is a lookup field or URL, the value of the field is displayed as a link.

 

outputtext :

 

Displays text on a Visualforce page.

 

outputtext is a good option...you need to retrieve the name in the query if you are using it...

 

ErikssonEriksson

Hi,

 

This is easy to display the account name but not a link using the outputText component.

try this:

 

Account: <apex:outputText value="{!X360_Contract_Cycle__c.Account__r.Name}" />

 You have to select the Account__r.Name from the object before using it.

 

Cheers

 

 

This was selected as the best answer
ocortinasocortinas

Like Eriksson mention the best way is to retriebve the name from the relation:

Account: <apex:outputText value="{!X360_Contract_Cycle__c.Account__r.Name}" />

 

If this dosn't work for you then you have to get the value on a String throw the controller associated to the page and then display that string, but this is not the correct way to do it.

 

Does some of this help to you?

Let me know.

Regards,

Olivedr

src0010src0010

 


Eriksson wrote:

Hi,

 

This is easy to display the account name but not a link using the outputText component.

try this:

 

Account: <apex:outputText value="{!X360_Contract_Cycle__c.Account__r.Name}" />

 You have to select the Account__r.Name from the object before using it.

 

Cheers

 

 


 

That did it!  I used the dot notation in SOQL previously, but did not think about that being available for outputText to establish the relationship.  Thanks for everyones help!

 

Nishant Dubey 7Nishant Dubey 7
apex:outputText: Displays text on a Visualforce page.

apex:outputField: A read-only display of a label and value for a field on a Salesforce object.

<apex:page controller="SampleTest" tabStyle="Account">
<apex:form >
<apex:pageMessages />
    <apex:pageBlock id="pgb">
        <apex:pageBlockSection columns="1">
            <apex:outputText >Sample Output Text</apex:outputText>
            <apex:outputField value="{!acct.Name}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>

</apex:page>

Apex Class:

public class SampleTest {
    public Account acct {get;set;}
    
    public Sample() {
       acct = [SELECT Name, Industry FROM Account LIMIT 1];
    }
}
Barry Wang 11Barry Wang 11
Hello, I got a question for retriving data. For example, if I use code like this: <apex:outputtext value="{!Case.Owner.Name}" /> and I can get a text show on my web page. But how can I know where does each value after dot come from, is that simply (object name) . (field name) . (data wanna retrive). But how can I know the exact name of data that I wanna retrive?  The example I showed is a bad example, cuz I assume that the name of data I wanna retrive maybe call Name, yet I dont know where to find it.     Thanks for helping.