+ Start a Discussion
snovvblindsnovvblind 

Embedding User Profile Pic in Record based on look-up field to user.

If there's a lookup to a user within a record, how do I write a Visualforce page and controller to display that user's profile picture within the record itself? I wanted to see if you had any tips and suggestions on the exact coding itself.

 

Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
Rahul SharmaRahul Sharma

Hey you are just close enough to the solution. Modify your extension as below:

 

Page(just for reference, no change):

<apex:page StandardController="Flight_Resource__c" extensions="profileImageUrl">
    <apex:image id="profileImage" url="{!profileImageUrl}" />
</apex:page>

 Controller(Just have added a parameter to the constructor for making it work as extension):

public class profileImageUrl {
    public String profileImageUrl { get; set; }
    List<user> lstuser;
   
    // As this is an extension of standard controller, It must have a parameterized constructor having instance of standard controller.
    public profileImageUrl (ApexPages.StandardController controller) {
         lstuser = [select FullPhotoUrl from User where Id =: UserInfo.getUserId()];
         profileImageUrl=lstuser[0].FullPhotoUrl;  
    }
}

 

All Answers

snovvblindsnovvblind

I do have some sort of a start on this.

 

I'm getting the following error while saving the Visualforce:

 

Error: Unknown property 'profileImageUrl' referenced in ChatterPic

 

Controller:

 

public class profileImageUrl {
   public String profileImageUrl { get; set; }
   List<user> lstuser;
   
   public profileImageUrl () {
        lstuser = [select FullPhotoUrl from User where Id =: UserInfo.getUserId()];
        profileImageUrl=lstuser[0].FullPhotoUrl;  
   }
}

 

Visualforce:

 

<apex:page>
<apex:image id="profileImage" url="{!profileImageUrl}" />
</apex:page>

 

Rahul SharmaRahul Sharma

snovvblind, You created a controller and page, but you forgot to bind them. use controller attribute in apex:page tag.

Note: While using a list, always ensure if its size is greater than 0, before indexing the list.

 

<apex:page controller="profileImageUrl">
<apex:image id="profileImage" url="{!profileImageUrl}" />
</apex:page>

 

snovvblindsnovvblind

Hi Rahul,

 

How do I then embed the visual force page into a custom object?

Rahul SharmaRahul Sharma

In the record page layout, you would be able to add the page to the layout.

Just make sure you use custom object as the standard controller in your page. Use extension instead of extension.

snovvblindsnovvblind

I'm using the following visualforce page now, but I'm running into the following error:

 

 

Error: Unknown constructor 'profileImageUrl.profileImageUrl(ApexPages.StandardController controller)' Create Apex method 'profileImageUrl.profileImageUrl(ApexPages.StandardController controller)'

 

<apex:page StandardController="Flight_Resource__c" extensions="profileImageUrl">
<apex:image id="profileImage" url="{!profileImageUrl}" />
</apex:page>

 

snovvblindsnovvblind

I checked out this topic:

 

http://boards.developerforce.com/t5/Visualforce-Development/Standard-controller-and-custom-controller-in-one-apex-page/td-p/115620

I just can't figure out how to modify my controller so that I'm passing in the controller into my vf page properly. I'm a little new to both apex and visualforce. Thanks!

Rahul SharmaRahul Sharma

Hey you are just close enough to the solution. Modify your extension as below:

 

Page(just for reference, no change):

<apex:page StandardController="Flight_Resource__c" extensions="profileImageUrl">
    <apex:image id="profileImage" url="{!profileImageUrl}" />
</apex:page>

 Controller(Just have added a parameter to the constructor for making it work as extension):

public class profileImageUrl {
    public String profileImageUrl { get; set; }
    List<user> lstuser;
   
    // As this is an extension of standard controller, It must have a parameterized constructor having instance of standard controller.
    public profileImageUrl (ApexPages.StandardController controller) {
         lstuser = [select FullPhotoUrl from User where Id =: UserInfo.getUserId()];
         profileImageUrl=lstuser[0].FullPhotoUrl;  
    }
}

 

This was selected as the best answer
HariPHariP
I ran this query by with my user id and it said no such column?

select FullPhotoUrl from User where Id = '500.....'