Upload Chatter Profile Pic Using Apex

ConnectApi makes out job easier, using connectAPi we can achieve this as follows

blob picContect = res.getBodyAsBlob();
// get content into picContent(of Blog Type)

ConnectApi.BinaryInput fileUpload = new ConnectApi.BinaryInput(picContect, 
'image/jpg', '<<Pic Name>>');
ConnectApi.Photo photoProfile = ConnectApi.ChatterUsers.setPhoto(<<communityId>>, userId, fileUpload);

Tada!!! thats it!

Input of Community Id goes likes this

  • Internal - **null**
  • Customer Community - **navigate to community and copy id from url**
  • Partner community - **navigate to community and copy id from url**
  • Subscribe to Phanindra Mangipudi

    Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
    jamie@example.com
    Subscribe