3 Replies Latest reply on Dec 17, 2017 12:43 PM by Paul Donders

    Import Chatter Profile Photos from Active Directory

    Adi Leibowitz
      Share This:

      SalesForce users can independently upload their own Chatter profile photos, however some organizations prefer a more boring standardized approach, asking that users' photos will be imported automatically from Active Directory.


      For those of you who are using Pentaho to import user data, this is achievable using only a few simple lines of code and some minor configuration changes:


      1. Add a custom field to the user object which will hold a byte string representing the user photo (this string will be pulled from AD using Pentaho)


      2. In Pentaho, map the thumbnailPhoto AD field to the custom field you have just created (userPicHexString in our case)


      3. Add a trigger on the user object like below (or add the code within the for loop to triggers/classes already deployed in your ORG):


      trigger updateUserPhoto on User (after update, after insert) {
          Blob userPicBlob;
          ConnectApi.BinaryInput userPhotoBinInput;
          for (User currUser : Trigger.new){
              if (!String.isBlank(currUser.userPicHexString__c))
              userPicBlob = EncodingUtil.convertFromHex(currUser.userPicHexString__c);
              userPhotoBinInput = new ConnectApi.BinaryInput(userPicBlob,'image/jpg','userPhoto.jpg');
              ConnectApi.UserProfiles.setPhoto('internal', currUser.Id, userPhotoBinInput);


      That's it. Information from the thumbnailPhoto field in Active Directory, which looks like this, will be stored in the custom field you have created, and used to generate profile photos:




      Don't forget to test before deploying in production, use at your own risk, etc.


      Happy Holidays!