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.
Attribution to: Priyanka
Possible Suggestion/Solution #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>
Attribution to: techtrekker
Possible Suggestion/Solution #2
Finally, I wrote a scheduler class and updated the picture at regular intervals.
Anybody if you find any other solution, please let me know.
Attribution to: Priyanka
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/1977