I am creating my own profile page (branding/security reasons) and I ran into an issue where the user is not able to change their profile image.

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

public PageReference upload() {
    Blob b;
    b = document.body;
    Community community = [SELECT Id FROM Community WHERE Name = 'Customer Portal' limit 1];
    String userId= UserInfo.getUserId();
    ConnectApi.Photo photo = ConnectApi.ChatterUsers.setPhoto(community.Id, userId,  new ConnectApi.BinaryInput(b,'image/jpg','userImage.jpg'));
    return null;

My code works for an internal user but the external user it always gives me an Insufficient Privileges error when return document is called. If I change it so that it returns null my code runs, just does not set the image. Is a specific permission or different way of getting the image blob and assigning it to ConnectAPI.photo?

Here is the needed VF in order to run the code,

<apex:form enctype="multipart/form-data">
<apex:pageBlock title="Upload a File">

  <apex:pageBlockButtons >
    <apex:commandButton action="{!upload}" value="Save"/>

  <apex:pageBlockSection showHeader="false" columns="2" id="block1">

    <apex:pageBlockSectionItem >
      <apex:outputLabel value="File" for="file"/>
      <apex:inputFile value="{!document.body}" filename="{!document.name}" id="file"/>



  • whats the error you are getting on screen when you run as external user ?External user is community user? – Mohith Shrivastava Sep 16 '14 at 14:13
  • Yes external user is community user, license is Partner Community. I get Insufficient Privileges error when I try to upload the image. If I change document to return null the code runs but does not change/set the image. – Grady D Sep 16 '14 at 14:15

It looks from your code as though you're setting the image as a document related to the chatter object, but I can't ascertain that for certain from your code. If so, I think you should be okay provided the user has ownership of that record and the IsPublic field is set to true which I don't see. If you're simply creating a Document, a Partner Community User doesn't have access to it unless its related to certain other Objects which could be the issue that you're having.

If its not related to an Object they have access to, it also will need to be set to public for them to view it from a Community unless you've set up other sharing rules to provide access for them. See Communities User Licenses for more on what they have access to.

  • Do you know if it is possible to accomplish what I am wanting without saving the image locally? – Grady D Sep 16 '14 at 15:43
  • You're going to need to save it someplace. Presumably you could save it to a remote host and provide the link to it if that's what you're asking. I'd think you could also save it to a custom object if you have one to spare or as a related document to something you know the user has access to. A partner should have access to related attachments on Contacts, but they won't own the contact record for themselves. – crmprogdev Sep 16 '14 at 15:51
  • What if I skipped the whole document section and just grabbed the blob, currently document.body, and saved that to blob b? Is that possible? – Grady D Sep 17 '14 at 14:18
  • I don't think that would be possible since blob b wouldn't be a Salesforce object that's defined. – crmprogdev Sep 17 '14 at 15:28
  • Here's a suggestion. The profile image is part of the User's contact info. Why not try saving it as an attachment to the Contact Object where it actually belongs and they also have access to? Take a look at this doc for more: help.salesforce.com/help/pdfs/en/…. – crmprogdev Sep 17 '14 at 16:51

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.