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
MoDiggityMoDiggity 

"Invalid user identifiers" when sending chatter message to portal user from apex

I have in my code: ConnectApi.ChatterMessages.sendMessage('Hello World', '[portal user id]');

But it fails saying "Invalid user identifiers"

This is a community user.  Does that mean they can't receive direct chatter messages? This same piece of code works fine for internal users.
ShashankShashank (Salesforce Developers) 
You should pass in the community ID as well since chatter in a community is not in any way connected with the internal chatter.

Something like this:

ConnectApi.ChatterMessages.sendMessage('community id','Hello World', '[portal user id]');

Reference: https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_ConnectAPI_ChatterMessages_static_methods.htm#apex_ConnectAPI_ChatterMessages_sendMessage_2
sirisha kotarusirisha kotaru
I am getting the following error 'System.NoAccessException: You do not have permission to use Chatter Messages. Your organization may not have permission or may not have enabled Chatter Messages. If you're in a network, Chatter Messages may not be enabled for the network' . 

Do we have to unable Chatter Messages for the community.
ShashankShashank (Salesforce Developers) 
As per the comment from product management in this delivered idea, you may have to turn on chatter messages for the community.
sirisha kotarusirisha kotaru
Thanks Shashank .. can you please let me know , how to turn on chatter messsages for the community. Chatter Messages are turned on in my org.
Waqar Hussain SFWaqar Hussain SF
I am also facing this problem. I am using chatter rest api to send a message. When i send message to any other user than the community user the message send But  When i send message to a community user it shows me the error [{"errorCode":"INSUFFICIENT_ACCESS","message":"Invalid user identifiers: 005w0000004ow2w"}]

Anybody have any idea or solution about that case. Why the message is not sending to community user through chatter rest api?
Sukrutha S M 22Sukrutha S M 22
I am also facing this issue.I use connectAPI.ChatterMessage.sendMessage(communityid,message,recipientId) it does not work with internal users or community users.Error in the console is "ExceptionConnectApiException:[errorCode=INSUFFICIENT_ACCESS]: Invalid user identifiers: 0052800000410bo" .

Anyone has any clue what could be the cause? 
Juan SpagnoliJuan Spagnoli
There are 2 different fields in Network object:

OptionsDirectMessagesEnabled and OptionsPrivateMessagesEnabled

The first one is what you can setup in the Community Setting, but the second one is not in the UI and is the one that allow you to send Chatter Messages to Communities Users. You can query them using the Workbench:

SELECT Id, Name,OptionsDirectMessagesEnabled,OptionsPrivateMessagesEnabled FROM Network

Now... How can we turn on this setup? I could do it making a PATCH over the record:

/services/data/v30.0/sobjects/Network/[NETWORK_ID]

{"OptionsPrivateMessagesEnabled":true}

Then, you will able to send Private Messages using ConnectApi.ChatterMessages.sendMessage. Take in consideration that there is not standard component in Community for Private Messages, so you will have to develop a custom one.

Regards