Search code examples
salesforceapex-codevisualforceforce.com

Visualforce: How to display user's account using the $User


I have a visualforce component which I use for displaying the user's name. Currently I am doing it using the following:

!$User.FirstName} {!$User.LastName}

Is there any way I can display the User's Account as well using this without writing SOQL. I would not like to create a controller just to display the user's account and am hoping there is a simpler and easier way using just Visual force.

I did try !$User.Contact.Account}

But it gave me an error.

Thanks.


Solution

  • Here are two things you may want to try:

    1. Reference the Account Name from the $User Visualforce global variable.

      {!$User.Contact.Account.Name}

    2. If that doesn't work, create a new formula field on the User object named Contact Account Name with this formula: Contact.Account.Name. Once you have created that formula field, you should be able to reference it in Visualforce using: {!$User.Contact_Account_Name__c}.