7

The chatter profile picture url is saved in the User FullPhotoUrl field.

If we try to modify the picture/upload a new picture in the chatter profile image, the trigger in the user object is not triggered.

Is there any way to invoke a trigger when the chatter profile image is modified.

trigger UpdateChatterPicture on User (after insert, after update) { List<UserPhoto__c> lstInsertPhoto = new List<UserPhoto__c>(); List<UserPhoto__c> lstUpdatePhoto = new List<UserPhoto__c>(); List<UserPhoto__c> lstUserPhoto = new list<UserPhoto__c>(); Map<Id,UserPhoto__c> MapUserPhotoId = new map<id,UserPhoto__c>(); List<UserPhoto__c> lstAllUsrPhoto = new List<UserPhoto__c>(); lstUserPhoto = [select Id, Name, User__c, (select id from attachments) from UserPhoto__c where User__c in: trigger.newmap.keyset()]; System.debug('Trigger:lstUserPhoto='+lstUserPhoto); for(UserPhoto__c userphoto : lstUserPhoto) { MapUserPhotoId.put(userphoto.User__c , userphoto); } System.debug('Trigger:MapUserPhotoId='+MapUserPhotoId); for(User user : trigger.new) { if(Trigger.IsInsert && user.isIVExchangeUser__c == true) { UserPhoto__c photo = new UserPhoto__c(); photo.Name = user.Name; photo.User__c = user.Id; photo.PhotoURL__c = user.FullPhotoURL; lstInsertPhoto.add(photo); System.debug('Trigger:photo='+photo); } else if(Trigger.IsUpdate && user.isIVExchangeUser__c == true) { user oldUsr = Trigger.oldMap.get(user.Id); if (oldUsr.FullPhotoURL != User.FullPhotoURL) { UserPhoto__c usrphoto = MapUserPhotoId.get(user.id); usrphoto.PhotoURL__c = User.FullPhotoURL; lstUpdatePhoto.add(usrphoto); System.debug('Trigger:Updatephoto='+usrphoto); } } } try { insert lstInsertPhoto; update lstUpdatePhoto; } Catch(Exception ex) { } lstAllUsrPhoto.addall(lstInsertPhoto); lstAllUsrPhoto.addall(lstUpdatePhoto); System.debug('Trigger:lstAllUsrPhoto'+lstAllUsrPhoto); //calling class to insert attachment clsUpdateUserPhotoAttachment.UpdateUserPhotoAttachment(lstAllUsrPhoto); }

Thanks in advance.

  • Can you post up some sample code? – Davin Casey Oct 5 '12 at 14:33
  • You need to first find whether on change of the picture is your field on the user getting updated or not ?If yes then there can be some trigger issues and may require debug.Can you put more detail into question – Mohith Shrivastava Oct 5 '12 at 15:12
  • Yes it is getting updated. I checked it via workbench. I debug the trigger also but the trigger is not invoked during the photo upload – Priyanka Oct 5 '12 at 15:17
  • DavinC, added my code in my question – Priyanka Oct 5 '12 at 15:31
  • 1
    there's no trigger fired because there's no value stored, the photoUrl fields are calculated when the row is read (like a formula field), not a stored value. – superfell Oct 5 '12 at 15:36
1

Just reading the other question you posted where your objective is to actually display the chatter photo on a vf page on the portal.

I read you went down this custom object route coz the Api route wasn't playing ball.

You can use the solution in the blog you mentioned (http://blogs.developerforce.com/developer-relations/2011/03/accessing-chatter-user-pics.html) even with a session id, you don't need an oauth token.

To get a sessionId all you need is a login call which you can obtain using the Ajax toolkit http://www.salesforce.com/us/developer/docs/ajax/index.htm

Here's a bit of sample code that fetches the photo at page load and redirects to the url

<apex:page>

<script src="../../soap/ajax/26.0/connection.js" type="text/javascript" />
<script type="text/javascript" >
window.onload = connectRemotely;

function connectRemotely(){
     var result = sforce.connection.login("USERNAME@DOMAIN.COM", "PASSWORD + SECURITY TOKEN");
     alert(result.sessionId);
     window.location.href = "https://c.XXX.content.force.com/profilephoto/USERID/F?oauth_token=" + result.sessionId;
     }
     </script>

</apex:page>
|improve this answer|||||
  • Just curious - did this answer your question ? – techtrekker Oct 8 '12 at 13:32
  • In the given solution, how can I provide external user password and security token? – Priyanka Oct 9 '12 at 7:31
  • Could you not just have an integration user which you use. Oauth is preferable I guess, but if that's too complex, I reckoned this was a workaround. – techtrekker Oct 9 '12 at 7:35
  • FYI, my understanding is that the AJAX API, which is used by this solution, will not be supported in Salesforce Communities, which are replacing Customer Portals as of Summer '13. – Benj May 1 '13 at 18:35
1

Finally, I wrote a scheduler class and updated the picture at regular intervals.

Anybody if you find any other solution, please let me know.

|improve this answer|||||
  • How did you able to convert FullPhotoURL to a blob in a scheduler without a session id to pass for oAuthToken? I am trying a similar thing but running into problem when I execute in batch mode. Appreciate your help on this – user2623 Mar 28 '13 at 21:40
  • ConnectAPi.getPhoto provides standardEmailPhotoURL, which is public url and can be used to get blob without oAuth Token. – Ashish Narang Jun 25 '15 at 5:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.