function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
modomodo 

How to retrieve user picture with record OwnerId and display in visual force page?

I have been attempting to access an OwnerId's small or large photo, directly from visualforce with no success. I have also attempted to simply access the $User.SmallPhotoUrl but visualforce compile complains that the field does not exist. Yet I can see the field via schema explorer in eclipse. Every other User string field evaluates successfully. Is there a simple way without writing a controller method to URLFOR or equivalent the user's image rom a record OwnerId assigned to that user.

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
modomodo

Thank you for the response. The response did not completely answer the root question of capturing OwnerId vs UserId but it got me on the right track (and did respond to the UserId part). This is the function I wrote to retrieve the Url based on the object's owner.Id. And then a small snippet for outputting on a page

 

function getOwnerPhoto (OwnerVar){

sforce.connection.sessionId ="{!$Api.Session_ID}";
var result= sforce.connection.query("select SmallPhotoUrl from User where Id = ' "+ OwnerVar+" ' ");
var records = result.getArray("records");

document.write("<img src='"+records[0].SmallPhotoUrl+"' alt='Owner Photo' width=48 height=48 />");

}

 

Then in the body to diplay on a page inline with other elements:

 

<script> getOwnerPhoto('{!CustomObjectX__c.OwnerId}'); </script>

 

I still feel like something is broken in the schema as I should be able directly return this with an id pointer in hand (e.g. OwnerId.SmallPhotoUrl)

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

 

Try the below code snippet as reference:

 

  <script src="../../soap/ajax/24.0/connection.js" type="text/javascript"></script>

    <script>

    try

    {

       sforce.connection.sessionId ="{!$Api.Session_ID}";

       var result= sforce.connection.query('select id,SmallPhotoUrl from User limit 1');

       alert(result);

     }

     catch(ex)

     {

     alert(ex);

     }

    </script>

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

modomodo

Thank you for the response. The response did not completely answer the root question of capturing OwnerId vs UserId but it got me on the right track (and did respond to the UserId part). This is the function I wrote to retrieve the Url based on the object's owner.Id. And then a small snippet for outputting on a page

 

function getOwnerPhoto (OwnerVar){

sforce.connection.sessionId ="{!$Api.Session_ID}";
var result= sforce.connection.query("select SmallPhotoUrl from User where Id = ' "+ OwnerVar+" ' ");
var records = result.getArray("records");

document.write("<img src='"+records[0].SmallPhotoUrl+"' alt='Owner Photo' width=48 height=48 />");

}

 

Then in the body to diplay on a page inline with other elements:

 

<script> getOwnerPhoto('{!CustomObjectX__c.OwnerId}'); </script>

 

I still feel like something is broken in the schema as I should be able directly return this with an id pointer in hand (e.g. OwnerId.SmallPhotoUrl)

This was selected as the best answer