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
JuanBessJuanBess 

Problem showing User Image

Hi,

I have a problem when override the user image. The image link change to something like this:

https://na7.salesforce.com/userphoto?id={!userId}&v=2&s=T

and before has v=1 .

I wonder where i can get the version number of the image or where this images are stored to check the size of the related images.

Thanks in advance,

Juan.

cloudcodercloudcoder

In the beta release of Chatter the version number is unfortunately not available. One work around which I have used is to create a custom field, image_version__c on the User object which can be manually updated. You can then change your code to something like this:

 

https://na7.salesforce.com/userphoto?id={!userId}&v={!user.image_version__c}&s=T

 

It is not ideal as you still need to manually update the value on the user object but it does provide an interim solution.

 

HTH

 

Q

JuanBessJuanBess

I found another solution meanwhile they provide us a more elegant way to get the photo version. It's not the best one, but at least work and don't require manual changes.

This is the solution if you are interested:

 

List<User> users = [select id from Users];
String yourDomain = 'na7.salesforce.com';
Map<Id, String> userImages = new Map<Id, String>();
for (User iterUser : users) {
   PageReference pageRef = new PageReference('https://' + yourDomain + '/_ui/core/userprofile/UserProfilePage?u=' + iterUser.Id);
   String photoVersion = pageRef.getContent().toString();
   photoVersion = photoVersion .split('(?i)<div id="photoSection" class="photoSection">', 2)[1];
   photoVersion = photoVersion .split('(?i)&amp;s=', 2)[0];
   photoVersion = photoVersion .split('(?i)v=', 2)[1];
   String userImg = '<img src="/userphoto?id=' + iterUser.id + '&v=' + photoVersion + '&s=T" />';
   userImages.put(iterUser.id, userImg);
}

 

 

 

Regards,

Juan.