2

I have a problem when I trigger on the User object: I can't get the profile photo url.

On this simple code I made a trigger to an User update and I send me by mail the fields FirstName LastName and MediumPhotoUrl from the updated user.

I get FirstName and LastName well but impossible to get MediumPhotoUrl (null), I don't understand why I can't access this field.

In a classic Apex class I can do [SELECT Id, MediumPhotoUrl from User etc...] So I don't know why I can't access to this field here ?

Do you have any idea ?

Thank you

trigger UpdateUserToSendBird on User (before update) {

    for(User usr : Trigger.new) {       
        User oldUser = Trigger.oldMap.get(usr.Id);

        if(oldUser.SendBird_Synchro__c == true){

            String userId = usr.Id;
            String userName = usr.Name;
            String total = 'Name = '+usr.FirstName+ ' '+usr.LastName + ' photo = '+usr.FullPhotoUrl + ' ' + usr.MediumBannerPhotoUrl + ' ' + usr.BannerPhotoUrl + ' '+usr.SmallPhotoUrl;
            EmailManagerBis.sendMail('florian.joubert1@gmail.com', 'test update',total );

        }

        else{

            system.debug('Not sendbird User');
        }
    }
}

EDIT : When I update a classic field on the user profile (first name, last name, AboutMe, ...) it launches the trigger. However, when I update the profile picture or the banner, the trigger does not launch, as if these 2 fields were not part of the User object, or as if modifying the photos is not considered as an update

Updated code to test other fields, result :

Result trigger

1

It appears to me that your trigger may be using the incorrect field. According to the Object Reference for User, there are 5 possible fields that a user photo can be held in, the most important one being the FullPhotoURL. Here are the names of all the fields:

  • BannerPhotoUrl: The URL for the user's banner photo. (API 36 & later)
  • FullPhotoUrl: The URL for the user's profile photo.
  • MediumBannerPhotoUrl: The URL for the medium sized user profile banner photo.
  • SmallBannerPhotoUrl: The URL for the small user profile banner photo.
  • SmallPhotoUrl: The URL for a thumbnail of the user's profile photo.

EDIT

In response to comments...

I've looked at your code again and I see that your trigger doesn't use the correct field name for a Medium Photo. The correct field to use is MediumBannerPhotoUrl. I recommend you at least TRY changing the code in your trigger to see if it resolves your issue.

  • Thank you for your response. Unfortunately I had already tested all those fields, with the same result : null (I should have mentioned that). The MediumPhotoUrl is also correct, I use it in several Apex Classes – Florian Joubert Jul 24 '18 at 12:57
  • @FlorianJoubert I had meant to mention that about 1-1/2 years ago sharing was added to the User Object. Check your OWD to see what they are and whether that might be affecting your trigger and your results. – crmprogdev Jul 24 '18 at 14:48
  • @ crmprogdev I had already tested thoses field, but I have updated the code and the result in my post. The MediumPhotoUrl is correct, it's in my User Object with the label : "Url for medium profile photo" as I want to get the profile picture of an user. But I tried all photos fields. I think the problem is how thoses (pictures) fields can be read in a trigger and why they react differently from other fields ? – Florian Joubert Jul 25 '18 at 7:41
  • @FlorianJoubert I recommend you create a unit test method to help you determine why this isn't working for you. By creating the test data yourself and using different RunAs users (not just an Admin) and also testing different "types" of users, you should be able to better isolate the source of the issue. – crmprogdev Jul 28 '18 at 14:42

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.