0

I want to follow a record via chatter api for a specific user, it's possible for users to make other users to follow a record, specifically I use this method:
ConnectApi.ChatterUsers.follow(null, userId, caseId);

When I run from system administrator everything works great, but once I run from a different profile it results in this error:
System.NoAccessException: Insufficient Privileges: You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary.

I have the following options checked in profile settings:

  • Chatter Internal User
  • Moderate Chatter
  • Manage Chatter Messages and Direct Messages
  • Manage Unlisted Groups
  • Create and Own New Chatter Groups

And I checked profile has view/ edit access of the target record.

Does anyone knows what permissions are missing? is it a bug?

  • under system permissions, does the profile have "API Enabled" ? if not, once you enable it, do you still run into this issue? – glls Oct 23 '17 at 14:21
  • @glls yes, option "API Enabled" is active, still an issue. Also I run code from a test class with System.runAs(fromUser) where the user is of mentioned profile. – NGix Oct 23 '17 at 14:44
  • does the profile in question have access to the record? – glls Oct 23 '17 at 14:56
  • The ConnectApi methods don't support System.runAs: developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…. Also, can you use 'me' as the userId to ensure that it's the current user that's doing the following? – alouie Oct 23 '17 at 22:28
  • 1
    For your scenario, you'll probably want to insert an EntitySubscription record instead of using ConnectApi.ChatterUsers.follow: developer.salesforce.com/docs/atlas.en-us.sfFieldRef.meta/… – alouie Oct 30 '17 at 2:21
0

Only Admins or the context user can make that API Call.

Most of the Chatter APIs are intended to be ran for the Context User.

  • we have users that aren't admins but want them being able to make other users to follow cases, any ideas where i can read about the limitation you mentioned? – NGix Oct 25 '17 at 13:34
  • This might be the only place where its spelled out: developer.salesforce.com/docs/atlas.en-us.apexcode.meta/… Chatter in Apex methods don’t run in system mode, they run in the context of the current user (also called the context user). The methods have access to whatever the context user has access to. Chatter in Apex doesn’t support the runAs system method. When a method takes a subjectId argument, often that subject must be the context user. In these cases, you can use the string me to specify the context user instead of an ID. – Paul B. Oct 26 '17 at 18:31

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.