34
When you click Save, you will see your first name and an empty account name. This is because you haven’t told the Visualforce page
which account record to display. Go to your URL and modify it so that you include the ID from Step 1. So instead of something like:
https://na3.salesforce.com/apex/accountDisplay
change it to something like:
https://na3.salesforce.com/apex/accountDisplay?id=0018000000MDfn1
In your case, change the identifier 0018000000MDfn1 to whatever you found in Step 1. You might need to change “na3” as well, to
whatever your salesforce instance currently is.
Now when you save your work, the account name displays:
Display Other Fields
Your accountDisplay page only displays the name field of the Account object. To find other fields to display for the object, from
the object management settings for accounts, go to the fields area. Click any field, such as Ticker Symbol. The Field Name field provides
the name that you can use in your own Visualforce pages. For example, for this particular field, the name is TickerSymbol.
Modify accountDisplay to include this field by adding the following paragraph after the existing one:
<p>Here's the Ticker Symbol field: {! account.TickerSymbol}</p>
Display Fields from Related Records
You can also display data from related records. For example, while viewing the object details for Account, you might have noticed that
the Account object has a field called Account Owner, and that its type is Lookup(User). In other words, this field has a relationship to a
User record. By clicking the Account Owner field label link, you’ll discover its Field Name is Owner.
The Owner relationship represents a User. And, if you go to the fields area from the object management settings for users, you’ll find
that User has a Name field. Let’s use this information to display it.
1. Modify accountDisplay to include this field by adding the following paragraph after the existing one:
<p>Here's the owner of this account: {! account.Owner.Name}</p>
The “dot notation” (account.Owner.Name) indicates that you want to traverse the relationship between the records. You know
that account.Owner indicates the Owner field of the account record. The extra name at the end indicates that the owner field isn’t
a simple field representing a String, but a relationship to another record (it’s a Lookup(User)), and that you’d like to get the record
represented by the value of the Owner field (it’s a User record), and display the Name field on that record.
Tip: If you’ve created your own custom objects (instead of using objects like Account) and want to know how to reference a field,
you have to follow a slightly different procedure. Go to the management settings for custom objects. Then select your object, and
then the field. The API Name now indicates the name of the field that you must use in your Visualforce pages. For example, if your
field was called Foo, its API Name is Foo__c, and you’d reference it with that name—something like:
{! myobject__c.foo__c}.
13
Display Other Fields
Introduction to Visualforce