Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

What is the expression to access User's Contact record fields in Visualforce? I need in for Customer Portal.

share|improve this question

2 Answers 2

up vote 0 down vote accepted

You can get the Contact record in your controller by using the UserInfo object and something along the lines of the following query. Then you can reference it in your Visualforce page.

public class YourController {
    public Contact userContact { get; set; }

    public YourController() {
        userContact = [
            Select Id, Name /*etc.,*/
            From Contact
            Where Id In (Select ContactId
                         From User
                         Where Id = :UserInfo.getUserId())
        ];
    }

}
share|improve this answer

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_user.htm

After quick look I believe {!$User.Contact.Email} etc should be ok.

share|improve this answer
    
{!$User.ContactId} is working but {!$User.Contact.Email} is not working. Do you know any workarounds? –  Suman Krishna Saha Jan 18 '13 at 8:18
    
Uh, that's a bad news. Try making a formula on User that'd reference the Contact's field? I suspect it won't work either though... Looks like you'll need an apex controller then or maybe some workflow/trigger that'd copy data over when source (Contact) changes. –  eyescream Jan 18 '13 at 8:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.