Thursday, February 21, 2019

How to update Chatter User Profile Photo using Connect API

The "connectapi" provide classess and static methods to access chatter data which is available through Chatter REST API. This is also referred as "Chatter in Apex". It exposes the data in localized and structured way.

Chatter in apex provides "UserProfiles" class which provides different methods to access information about users profile data.

Before version 35, "Chatterusers" class was there which was used to access information about users, such as activity, followers, subscriptions, files, and groups. Now this class is not available.

We will use UserProfiles class to update chatter user photo. You can either upload the image in documents or at any place. We need blob representation of that image and can be used to update profile photo using blob variable.

Below is sample code:

Document doc=[SELECT id, body FROM Document  WHERE Name='ProfilePhoto' LIMIT 1];
//set the photo on the user's profile
ConnectApi.UserProfiles.setPhoto(null, UserInfo.getUserId(), new ConnectApi.BinaryInput(doc.body,'image/jpg','user.jpg'));

I Have uploaded image in documents and then updating the profile photo on chatter.

setPhoto method require below attributes:
  • communityId (string)- specify the community Id or specify null for internal users
  • userid(string)- 15 digit or 18 digit user recordId 
  • Image details (ConnectApi.Binary​​Input) -  you need to specify the blob(content of file), MIME type of content and file name(string).

If you store profile photo in files, then you can use below syntax to update chatter profile photo:

ConnectApi.UserProfiles.setPhoto(null, UserInfo.getUserId(), '0690I00000D42WT',null);

This method takes 4 parameters
  • communityId (string)- specify the community Id or specify null for internal users.
  • userid(string)- 15 digit or 18 digit user's recordId.
  • fileId(string) - 15 or 18 digit file Id.
  • version number(integer) - Version number of the existing file. Specify either an existing version number, or null to get the latest version.
Hope this will help!!


  1. This particular is usually apparently essential and moreover outstanding truth along with for sure fair-minded and moreover admittedly useful My business is looking to find in advance designed for this specific useful stuffs… chiropodists drills

  2. This is my first visit to your web journal! We are a group of volunteers and new activities in the same specialty. Website gave us helpful data to work. childcare photographer

  3. Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! Gaelic Memories Photography

  4. Thank you for this fascinating post, I am happy I observed this website on Google. Not just content, in fact, the whole site is fantastic. dotcom secrets

  5. Interested in writing articles and don’t know where to find the right one? Then the service will help you find excellent articles in this, write any article for the order, or write an essay for you

  6. A round of applause for your mind blowing article. Much thanks to you. Fantastic.

  7. Places of work demand profiles complementing capabilities for a given occupation. Well known sites are upgraded by profile creators having a thorough foundation managing the current subjects. Márcio Miranda Maia

  8. Wedding cakes date back as far as the Roman Empire, long before the traditional iced white cake we know today was even conceived. But their evolution was not an overnight development, the wedding cake actually evolved from a number of traditions that were practiced in ancient Rome.

  9. With the beginning of computerized photography, it has become workable for everybody to learn and perform effective photo editing.
    car photo editing service

  10. Thanks for sharing this insightful guide on updating Chatter User Profile Photos using Connect API! 👨‍💻📸 The use of the 'User Profiles' class and handling image uploads via documents makes it clear and actionable. Great code snippet for those navigating through this process. Professional Car Photo Editing Service

  11. "BizTrader: Your wardrobe of business attire. 'Business For Sale' listings are the outfits in your entrepreneurial closet. Start dressing for success!"


  13. This comment has been removed by the author.

  14. Outsourcing a car photo editing service is an efficient and cost-effective way to improve the quality of your car images. It can help you achieve a consistent and aesthetically pleasing look for your car images, speed up the editing process, and reduce the time you spend editing.