+ Start a Discussion
Scott.MScott.M 

Get profile images from feed query

It's great that we can get profile urls using the fields on the User object. The problem is they don't seem to be assible from a feed query. So if I have a custom object Custom__c and I turn chatter on for it then try and get the feed with a query to Custom__Feed in apex. I can't access the profile images for the posts with CreatedBy.smallPhotoUrl because I get the following error:

 

No such column 'smallPhotoUrl' on entity 'Name'

 

So my question is, is there anyway to get the photo urls for the feed items in a single query or are we destined to do multiple queries and create wrapper classes to include the small photo urls :( I would really like to avoid this. 

Jia HuJia Hu

Yeah, you can't get smallPhotoUrl directly from Chatter object, but add only one SOQL will be fine, if you don't have too many users in the org. Like this,

AccountFeed af = [select id, createdbyid from AccountFeed limit 1];
Map<Id, User> usermap = new Map<Id, User>([select Id, smallPhotoUrl from user]);
System.debug(' --------- ' + usermap.get(af.createdbyid).smallPhotoUrl ) ;

If you got the createdbyid of the post, then you can get this user's photo link from the Map.

BharathimohanBharathimohan

Hello Scott,

 

SmallPhotoUrl gives the User Thumbnail Profile photo, which is available only in API version 20.0 and in later versions.

 

If you are using the query in AJAX, make sure you use API Version above 20 as below,

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}

 

 

If you are using the query in VF page, make sure the VF page version is above 20.

 

You can refer this LINK

 

 

Regards,

Bharathi
Salesforce For All

 

Mrk this post as solved, if it helps you