2

I am trying to show some notification for unread private message in a VF page of Community Site. In standard chatter page it used to notify the number of unread mails side by Messages link.

I did some search regarding this but didn't get clear idea how to achieve this. Please suggest some ideas how I can know that a user has some unread private messages or how I can show similar functionality as of standard chatter page in VF page.

3

This is all possible with the ConnectApi:

The ConnectApi namespace (also called Chatter in Apex) provides classes for accessing the same data available in Chatter REST API. Use Chatter in Apex to create custom Chatter experiences in Salesforce.

specifically with the ChatterMessages class.

Access and modify message and conversation data.

You can call getUnreadCount() which will

Returns the number of conversations the context user has marked unread. If the number is less than 50, it will return the exact unreadCount, and hasMore = false. If the context user has more than 50, unreadCount = 50 and hasMore = true.

However, your best bet is probably the overloaded method getUnreadCount(String communityId) which

Returns the number of conversations the context user has marked unread across their available communities. If the number is less than 50, it will return the exact unreadCount, and hasMore = false. If the context user has more than 50, unreadCount = 50 and hasMore = true.

Either way, the methods will return an instance of ConnectApi.UnreadConversationCount which you can use to then get the unreadCount, the number of unread messages.


Your final code snippet would look like:

ConnectApi.UnreadConversationCount unreadMessageCount = ConnectApi.ChatterMessages.getUnreadCount('communityId');
Integer numberOfUnreadMessages = unreadMessageCount.unreadCount;
  • Thanks Jesse for your suggestion.I tried the same and now I am able to get the unread count of private messages. – Arabinda May 31 '14 at 2:14
4

You can use the following line of code in your apex controller:

ConnectApi.ChatterMessages.getUnreadCount()

Returns the number of conversations the context user has marked unread. If the number is less than 50, it will return the exact unreadCount, and hasMore = false. If the context user has more than 50, unreadCount = 50 and hasMore = true.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_ConnectAPI_ChatterMessages_static_methods.htm#apex_ConnectAPI_ChatterMessages_getUnreadCount

  • Thanks Christian for your suggestion.Its really helped me. – Arabinda May 31 '14 at 2:12

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.