function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Amit VisapurkarAmit Visapurkar 


When I run the code get the following error.

Error: Compile Error: Method was removed after version 34.0: setPhoto

What is the new method?
Hi Amit,

you are correct this methid is available for the version 28-34
there is a new api method available is: setPhoto(communityId, userId, fileUpload)
If this doesn't work you may have to swich back to version 34 of apex and visualforce page and use the same method.

Arun KumarArun Kumar
Hi AMit,

Check below code, and see if you are missing something:
public without sharing class FileUploadController {

  public Document document {
    get {
      if (document == null)
        document = new Document();
      return document;

  public PageReference upload() {
    Blob b;
    document.AuthorId = UserInfo.getUserId();
    document.FolderId = UserInfo.getUserId(); // put it in running user's folder

      document.type = 'jpg'; 
      document.IsPublic = true;
      insert document;
     // ImageId = '06990000001HnuB';
      b = document.Body;
      //ConnectApi.ChatterUsers newPhoto = new ConnectApi.ChatterUsers();
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading file'));
      return null;
    } finally {
      document.body = null; // clears the viewstate
      document = new Document();

    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'File uploaded successfully : '+b));
    String communityId = null;
    String userId= UserInfo.getUserId();
    //ID fileId = ImageId;

    // Set photo
    ConnectApi.Photo photo = ConnectApi.ChatterUsers.setPhoto(communityId, userId,  new ConnectApi.BinaryInput(b,'image/jpg','userImage.jpg'));
    return null;


Arun KumarArun Kumar
Or if you are using version 35 or later 

Please use use "ConnectApi.UserProfiles" in place of "ConnectApi.ChatterUsers" like below:

ConnectApi.UserProfiles.setPhotoWithAttributes(communityId, userId, photo)

Please let me know if the helps.

As a common practice, if your question is answered, please choose 1 best answer.Additionaly you can give every answer a thumb up if that answer is helpful to you.