• Home
  • About
    • Leadership
    • Partners
    • Blogroll
  • Force-Squared Blog
    • Tips and Tricks
    • Configuration
    • Development
  • Support
    • Knowledge Base
    • Submit a Case
  • Is It Dreamforce Yet?

X-Squared On Demand

Salesforce solutions delivered

  • Home
  • About
    • Leadership
    • Partners
    • Blogroll
  • Force-Squared Blog
    • Tips and Tricks
    • Configuration
    • Development
  • Support
    • Knowledge Base
    • Submit a Case
  • Is It Dreamforce Yet?
  • Tips and Tricks
  • Configuration
  • Development
You are here: Home / Salesforce CRM / Configuration / Flexible Field Labels

Flexible Field Labels

March 23, 2009 by David Schach Leave a Comment

While making a Visualforce page to display a Zip/Country -> City, State, County application, it became obvious that labeling fields manually will not satisfy all users, especially international ones.

There are a few ways to include a field and its label on a Visualforce page.

The simplest, using OutputField:
VF Page (simple):

<apex:page standardcontroller="Account">
<apex:pageblock>
<apex:pageblocksection>
<apex:outputfield value="{!Account.Name}" />
</apex:pageblocksection>
</apex:pageblock>
</apex:page>

The most common (based on code shares and other observations) method allows one to use a label other than the one in Salesforce. It also allows combining of multiple fields while maintaining the standard style:

VF Page (common, but static):
<apex:page standardcontroller="Account">
<apex:pageblock>
<apex:pageblocksection columns="1">
<apex:pageblocksectionitem>
<apex:outputlabel value="Account Name" for="an" />
<apex:outputtext value="{!Account.Name}" id="an" />
</apex:pageblocksectionitem>
<apex:pageblocksectionitem>
<apex:outputlabel value="City, State, Zip" for="csz" />
<apex:outputtext value="{!Account.BillingCity}, {!Account.BillingState} {!Account.BillingPostalCode}" />
</apex:pageblocksectionitem>
</apex:pageblocksection>
</apex:pageblock>
</apex:page>

And a way to allow field label renaming and translations:

VF Page (more flexible, allowing for renaming and translations):
<apex:page standardcontroller="Account">
<apex:pageblock>
<apex:pageblocksection columns="1">
<apex:pageblocksectionitem>
<apex:outputlabel value="{!$ObjectType.account.fields.name.label}"  for="an" />
<apex:outputtext value="{!Account.Name}" id="an" />
</apex:pageblocksectionitem>
<apex:pageblocksectionitem>
<apex:outputlabel value="{!$ObjectType.account.fields.billingcity.label}, {!$ObjectType.account.fields.billingstate.label}, {!$ObjectType.account.fields.billingpostalcode.label}" for="csz" />
<apex:outputtext value="{!Account.BillingCity}, {!Account.BillingState} {!Account.BillingPostalCode}" id="csz"/>
</apex:pageblocksectionitem>
</apex:pageblocksection>
</apex:pageblock>
</apex:page>

So by using $ObjectType.account.fields.billingcity.label (and similar markup for other objects and fields) we can allow org-specific customizations to come into our code with no effort required.

There’s a catch (there always is). Note that there is no way to combine the three fields for City, State, and Zip (while using automatic renaming to help us with any customizations that the org has made) while maintaining proper labeling. In this case, the label for the combined field would be “Billing City, Billing State, Billing Zip/PostalCode.” In other words, we can use whatever the org prefers for each field, but the developer must choose the label, which must remain static.

The more astute administrators and developers will note that there is a solution available: Use a component and pass the field labels displayed to the component. Then, using custom labels and translations, the component could be made truly international. This is, however, beyond the scope of this post. But it is an idea for a future post…

And the most astute amongst you are probably saying, “A truly flexible labeling system would allow the word “State” for a US address, “Province” for Canadian and others, and would still be completely customizable and translatable. Yes, that would be nice. :)

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to email a link to a friend (Opens in new window) Email

Related

Filed Under: Configuration, Native Application, Salesforce, Visualforce Tagged With: Configuration, Force.com Platform, Visualforce

← Summer ’09 Logo Unveiled Hacking a Case Comment Trigger →

Share Your ThoughtsCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Is it Dreamforce Yet?

Find out!

Find us on the AppExchange

Mass Update Contacts 2.0

Get It Now

Recent Posts

  • Prevent Duplicate Emails on Leads
  • Duplicate Record Item Enrichment and Auto-Deletion Code
  • Lightning Component With Running User Information
  • ChatterBINGO is Now Open-Source
  • Display Only My Role’s Records on a Report

Post Categories

Popular Tags

#df09 #df10 Akismet Apex AppBuilder AppExchange Appirio Astadia Blogs Chatter Configuration Content DreamFactory Dreamforce Eclipse IDE Enterprise Force.com Builder Force.com Platform Google Infowelders Integration Just for fun Lightning New Developments New Features Partner Program PersonAccount Projects Publisher Salesforce Salesforce1 Salesforce for Google Apps sfdcverse Sites Visualforce Web-to X-Squared On Demand

Find Us Online

  • Twitter
  • Facebook
  • LinkedIn
  • RSS

Subscribe

RSS Feed Comments

Subscribe via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 164 other subscribers

Copyright © 2008–2025 X-Squared On Demand · Genesis Framework by StudioPress · WordPress · Log in

 

Loading Comments...