You need to sign in to do that
Don't have an account?
snovvblind
Displaying the Chatter Profile Pic based on a Lookup Field to the User Object
Hi All,
I'm interested in displaying the Chatter Profile pic within a Flight_Resource record, so that it points to a lookup relationship to a user in the User Object. I'm confused as to what the SOQL would look like to implement such a functionality.
I know this involves a custom apex controller and visualforce page. Here's the code below. Do you know how I can modify the controller so that I can get the above functionality to work properly? Any help will be much appreciated!
Page:
<apex:page StandardController="Flight_Resource__c" extensions="profileImageUrl"> <apex:image id="profileImage" url="{!profileImageUrl}" /> </apex:page>
Controller:
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; } }
Probably :controller.getRecord().get('OwnerId') instead.
I'm still learning apex. Can you please write it in a way that will make it compile? :)
Since you're just getting started, here's some other tips: Don't store information in a class variable if you don't need to (saves memory/view state size). Don't assume your list is non-empty, because it might be for some reason. Avoid using any variables when a simple loop will suffice. If this is supposed to be used in a repeating list (e.g. a list of Chatter posts), consider querying all the users that will have their profiles displayed at once, then passing that into your class.
I modified this slightely, and I'm getting the following error while the visual force component is embedded into the record:
Content cannot be displayed: SObject row was retrieved via SOQL without querying the requested field: Quarterly_Promotions__c.Employee_Name__c
This occurs because the "default SOQL query" did not include a field you expected. Try using controller.reset()/controller.addFields(), or, even better, use a hidden field (e.g. <apex:outputText value="{!Quarterly_Promotions__c.Employee_Name__c}" rendered="false"/> to force the query to include this field.