ChatterMessages Class

Access and modify message and conversation data.

Namespace

ConnectApi

Usage

Use Chatter in Apex to get, send, search, and reply to messages. You can also get and search conversations, mark conversations as read, and get a count of unread messages.

ChatterMessages Methods

The following are methods for ChatterMessages. All methods are static.

getConversation(conversationId)

Returns a conversation the context user has access to.

API Version

29.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterConversation getConversation(String conversationId)

Parameters

conversationId
Type: String
Specify the ID for the conversation.

Return Value

Type: ConnectApi.​Chatter​Conversation

getConversation(conversationId, pageParam, pageSize)

Returns a conversation the context user has access to.

API Version

29.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterConversation getConversation(String conversationId, String pageParam, Integer pageSize)

Parameters

conversationId
Type: String
Specify the ID for the conversation.
pageParam
Type: String
Specifies the page token to be used to view a page of information. Page tokens are returned as part of the response class, such as currentPageToken or nextPageToken. If you pass in null, the first page is returned.
pageSize
Type: Integer
Specifies the number of items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.

Return Value

Type: ConnectApi.​Chatter​Conversation

getConversation(communityId, conversationId)

Returns a conversation the context user has access to across their available communities.

API Version

30.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterConversation getConversation(String communityId, String conversationId)

Parameters

communityId
Type:String
Use either the ID for a community, internal, or null.
conversationId
Type: String
Specify the ID for the conversation.

Return Value

Type: ConnectApi.​Chatter​Conversation

A Chatter conversation and the related metadata.

getConversation(communityId, conversationId, pageParam, pageSize)

Returns a conversation from a specific page with a specific number of results the context user has access to across their available communities.

API Version

30.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterConversation getConversation(String communityId, String conversationId, String pageParam, String pageSize)

Parameters

communityId
Type:String
Use either the ID for a community, internal, or null.
conversationId
Type: String
Specify the ID for the conversation.
pageParam
Type:String
Specifies the page token to be used to view a page of information. Page tokens are returned as part of the response class, such as currentPageToken or nextPageToken. If you pass in null, the first page is returned.
pageSize
Type: Integer
Specifies the number of items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.

Return Value

Type: ConnectApi.​Chatter​Conversation

A Chatter conversation and the related metadata.

getConversations()

Returns the most recent conversations the context user has access to.

API Version

29.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterConversationPage getConversations()

Return Value

Type: ConnectApi.​Chatter​ConversationPage

getConversations(pageParam, pageSize)

Returns a specific page of conversations the context user has access to.

API Version

29.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterConversationPage getConversations(String pageParam, Integer pageSize)

Parameters

pageParam
Type: String
Specifies the page token to be used to view a page of information. Page tokens are returned as part of the response class, such as currentPageToken or nextPageToken. If you pass in null, the first page is returned.
pageSize
Type: Integer
Specifies the number of items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.

Return Value

Type: ConnectApi.​Chatter​ConversationPage

getConversations(communityId)

Returns the most recent conversations the context user has access to across their available communities.

API Version

30.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterConversationPage getConversations(String communityId)

Parameters

communityId
Type:String
Use either the ID for a community, internal, or null.

Return Value

Type: ConnectApi.​Chatter​ConversationPage

A list of Chatter conversations on a specific page.

getConversations(communityId, pageParam, pageSize)

Returns a specific page of conversations with a specific number of results the context user has access to across their available communities.

API Version

30.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterConversationPage getConversations(String communityId, String pageParam, Integer pageSize)

Parameters

communityId
Type:String
Use either the ID for a community, internal, or null.
pageParam
Type:String
Specifies the page token to be used to view a page of information. Page tokens are returned as part of the response class, such as currentPageToken or nextPageToken. If you pass in null, the first page is returned.
pageSize
Type: Integer
Specifies the number of items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.

Return Value

Type: ConnectApi.​Chatter​ConversationPage

A list of Chatter conversations on a specific page.

getMessage(messageId)

Returns a message the context user has access to.

API Version

29.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterMessage getMessage(String messageId)

Parameters

messageId
Type: String
Specify the ID for the message.

Return Value

Type: ConnectApi.​Chatter​Message

getMessage(communityId, messageId)

Returns a message the context user has access to across their available communities.

API Version

30.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterMessage getMessage(String communityId, String messageId)

Parameters

communityId
Type:String
Use either the ID for a community, internal, or null.
messageId
Type: String
Specify the ID for the message.

Return Value

Type:ConnectApi.​Chatter​Message

A Chatter message and all the related metadata.

getMessages()

Returns a list of the most recent messages the context user has access to.

API Version

29.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterMessagePage getMessages()

Return Value

Type: ConnectApi.​Chatter​MessagePage

getMessages(pageParam, pageSize)

Returns the specified page of messages the context user has access to.

API Version

29.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterMessagePage getMessages(String pageParam, Integer pageSize)

Parameters

pageParam
Type: String
Specifies the page token to be used to view a page of information. Page tokens are returned as part of the response class, such as currentPageToken or nextPageToken. If you pass in null, the first page is returned.
pageSize
Type: Integer
Specifies the number of items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.

Return Value

Type: ConnectApi.​Chatter​MessagePage

getMessages(communityId)

Returns a list of the most recent messages the context user has access to across their available communities.

API Version

30.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterMessagePage getMessages(String communityId)

Parameters

communityId
Type:String
Use either the ID for a community, internal, or null.

Return Value

Type: ConnectApi.​Chatter​MessagePage

The Chatter messages on a specific page.

getMessages(communityId, pageParam, pageSize)

Returns the specified page of messages with the specified number of results the context user has access to across their available communities.

API Version

30.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterMessagePage getMessages(String communityId, String pageParam, Integer pageSize)

Parameters

communityId
Type:String
Use either the ID for a community, internal, or null.
pageParam
Type: String
Specifies the page token to be used to view a page of information. Page tokens are returned as part of the response class, such as currentPageToken or nextPageToken. If you pass in null, the first page is returned.
pageSize
Type: Integer
Specifies the number of items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.

Return Value

Type: ConnectApi.​Chatter​MessagePage

The Chatter messages on a specific page.

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.

API Version

29.0

Requires Chatter

Yes

Signature

public static ConnectApi.UnreadConversationCount getUnreadCount()

Return Value

Type: ConnectApi.​​UnreadConversationCount

Example

ConnectApi.UnreadConversationCount unread = ConnectApi.ChatterMessages.getUnreadCount();

getUnreadCount(communityId)

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.

API Version

30.0

Requires Chatter

Yes

Signature

public static ConnectApi.UnreadConversationCount getUnreadCount(String communityId)

Parameters

communityId
Type:String
Use either the ID for a community, internal, or null.

Return Value

Type: ConnectApi.​​UnreadConversationCount

The number of unread messages in a conversation.

markConversationRead(conversationId, read)

Marks a conversation as read for the context user.

API Version

29.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterConversationSummary markConversationRead(String conversationId, Boolean read)

Parameters

conversationId
Type: String
Specify the ID for the conversation.
read
Type: Boolean
Specifies whether the conversation has been read (true) or not (false).

Return Value

Type: ConnectApi.​Chatter​ConversationSummary

markConversationRead(communityId, conversationID, read)

Marks a conversation as read or unread for the context user across their available communities.

API Version

30.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterConversationSummary markConversationRead(String communityId, String conversationID, Boolean read)

Parameters

communityId
Type:String
Use either the ID for a community, internal, or null.
conversationId
Type: String
Specify the ID for the conversation.
read
Type: Boolean
Specifies whether the conversation has been read (true) or not (false).

Return Value

Type: ConnectApi.​Chatter​ConversationSummary

The summary of a Chatter conversation, including the members of the conversation, Chatter REST API URL, and contents of the latest message.

replyToMessage(text, inReplyTo)

Adds the specified text as a response to a previous message the context user has access to.

API Version

29.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterMessage replyToMessage(String text, String inReplyTo)

Parameters

text
Type: String
The text of the message. Cannot be empty or over 10,000 characters.
inReplyTo
Type: String
Specify the ID of the message that is being responded to.

Return Value

Type: ConnectApi.​Chatter​Message

replyToMessage(communityId, text, inReplyTo)

Adds the specified text as a response to a previous message the context user has access to across their available communities.

API Version

30.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterMessage replyToMessage(String communityId, String text, String inReplyTo)

Parameters

communityId
Type:String
Use either the ID for a community, internal, or null.
text
Type: String
The text of the message. Cannot be empty or over 10,000 characters.
inReplyTo
Type: String
Specify the ID of the message that is being responded to.

Return Value

Type: ConnectApi.​Chatter​Message

A Chatter message and all the related metadata.

searchConversation(conversationId, q)

Returns the conversation the context user has access to with a page of messages that matches any of the specified search.

API Version

29.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterConversation searchConversation(String conversationId, String q)

Parameters

conversationId
Type: String
Specify the ID for the conversation.
q
Type: String
Required and cannot be null. Specifies the string to search. The search string must contain at least two characters, not including wildcards. See Wildcards.

Return Value

Type: ConnectApi.​Chatter​Conversation

searchConversation(conversationId, pageParam, pageSize, q)

Returns the conversation the context user has access to with a page of messages that matches any of the specified search.

API Version

29.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterConversation searchConversation(String conversationId, String pageParam, Integer pageSize, String q)

Parameters

conversationId
Type: String
Specify the ID for the conversation.
pageParam
Type: String
Specifies the page token to be used to view a page of information. Page tokens are returned as part of the response class, such as currentPageToken or nextPageToken. If you pass in null, the first page is returned.
pageSize
Type: Integer
Specifies the number of items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.
q
Type: String
Specifies the number of feed items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.

Return Value

Type: ConnectApi.​Chatter​Conversation

searchConversation(communityId, conversationId, q)

Returns the conversation the context user has access to with a page of messages that matches any of the specified search across their available communities.

API Version

30.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterConversation searchConversation(String communityId, String conversationId, String q)

Parameters

communityId
Type:String
Use either the ID for a community, internal, or null.
conversationId
Type: String
Specify the ID for the conversation.
q
Type: String
Specifies the number of feed items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.

Return Value

Type: ConnectApi.​Chatter​Conversation

A Chatter conversation and the related metadata.

searchConversation(communityId, conversationId, pageParam, pageSize, q)

Returns the conversation the context user has access to with a page of messages that matches any of the specified search across their available communities.

API Version

30.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterConversation searchConversation(String communityId, String conversationId, String pageParam, Integer pageSize, String q)

Parameters

communityId
Type:String
Use either the ID for a community, internal, or null.
conversationId
Type: String
Specify the ID for the conversation.
pageParam
Type: String
Specifies the page token to be used to view a page of information. Page tokens are returned as part of the response class, such as currentPageToken or nextPageToken. If you pass in null, the first page is returned.
pageSize
Type: Integer
Specifies the number of items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.
q
Type: String
Specifies the number of feed items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.

Return Value

Type: ConnectApi.​Chatter​Conversation

A Chatter conversation and the related metadata.

searchConversations(q)

Returns a page of conversations the context user has access to where member names and messages in the conversations match any of the specified search criteria.

API Version

29.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterConversationPage searchConversations(String q)

Parameters

q
Type: String
Required and cannot be null. Specifies the string to search. The search string must contain at least two characters, not including wildcards. See Wildcards.

Return Value

Type: ConnectApi.​Chatter​ConversationPage

searchConversations(pageParam, pageSize, q)

Returns a page of conversations the context user has access to where member names and messages in the conversations match any of the specified search criteria.

API Version

29.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterConversationPage searchConversations(String pageParam, Integer pageSize, String q)

Parameters

pageParam
Type: String
Specifies the page token to be used to view a page of information. Page tokens are returned as part of the response class, such as currentPageToken or nextPageToken. If you pass in null, the first page is returned.
pageSize
Type: Integer
Specifies the number of items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.
q
Type: String
Required and cannot be null. Specifies the string to search. The search string must contain at least two characters, not including wildcards. See Wildcards.

Return Value

Type: ConnectApi.​Chatter​ConversationPage

searchConversations(communityId, q)

Returns a page of conversations the context user has access to where member names and messages in the conversations match any of the specified search criteria across their available communities.

API Version

30.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterConversationPage searchConversations(String communityId, String q)

Parameters

communityId
Type:String
Use either the ID for a community, internal, or null.
q
Type: String
Required and cannot be null. Specifies the string to search. The search string must contain at least two characters, not including wildcards. See Wildcards.

Return Value

Type: ConnectApi.​Chatter​ConversationPage

A list of Chatter conversations on a specific page.

searchConversations(communityId, pageParam, pageSize, q)

Returns a specific page of conversations with the specified number of results the context user has access to where member names and messages in the conversations match any of the specified search criteria across their available communities.

API Version

30.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterConversationPage searchConversations(String communityId, String pageParam, Integer pageSize, String q)

Parameters

communityId
Type:String
Use either the ID for a community, internal, or null.
pageParam
Type: String
Specifies the page token to be used to view a page of information. Page tokens are returned as part of the response class, such as currentPageToken or nextPageToken. If you pass in null, the first page is returned.
pageSize
Type: Integer
Specifies the number of items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.
q
Type: String
Required and cannot be null. Specifies the string to search. The search string must contain at least two characters, not including wildcards. See Wildcards.

Return Value

Type: ConnectApi.​Chatter​ConversationPage

A list of Chatter conversations on a specific page.

searchMessages(q)

Returns a page of messages the context user has access to that matches any of the specified criteria.

API Version

29.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterMessagePage searchMessages(String q)

Parameters

q
Type: String
Required and cannot be null. Specifies the string to search. The search string must contain at least two characters, not including wildcards. See Wildcards.

Return Value

Type: ConnectApi.​Chatter​MessagePage

searchMessages(pageParam, pageSize, q)

Returns a page of messages the context user has access to that matches any of the specified criteria.

API Version

29.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterMessagePage searchMessages(String pageParam, Integer pageSize, String q)

Parameters

pageParam
Type: String
Specifies the page token to be used to view a page of information. Page tokens are returned as part of the response class, such as currentPageToken or nextPageToken. If you pass in null, the first page is returned.
pageSize
Type: Integer
Specifies the number of items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.
q
Type: String
Required and cannot be null. Specifies the string to search. The search string must contain at least two characters, not including wildcards. See Wildcards.

Return Value

Type: ConnectApi.​Chatter​MessagePage

searchMessages(communityId, q)

Returns a page of messages the context user has access to that matches any of the specified criteria across their available communities.

API Version

30.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterMessagePage searchMessages(String communityId, String q)

Parameters

communityId
Type:String
Use either the ID for a community, internal, or null.
q
Type: String
Required and cannot be null. Specifies the string to search. The search string must contain at least two characters, not including wildcards. See Wildcards.

Return Value

Type: ConnectApi.​Chatter​MessagePage

The Chatter messages on a specific page.

searchMessages(communityId, pageParam, pageSize, q)

Returns a specific page of messages with the specified number of results the context user has access to that matches any of the specified criteria across their available communities.

API Version

30.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterMessagePage searchMessages(String communityId, String pageParam, Integer pageSize, String q)

Parameters

communityId
Type:String
Use either the ID for a community, internal, or null.
pageParam
Type: String
Specifies the page token to be used to view a page of information. Page tokens are returned as part of the response class, such as currentPageToken or nextPageToken. If you pass in null, the first page is returned.
pageSize
Type: Integer
Specifies the number of items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.
q
Type: String
Required and cannot be null. Specifies the string to search. The search string must contain at least two characters, not including wildcards. See Wildcards.

Return Value

Type: ConnectApi.​Chatter​MessagePage

The Chatter messages on a specific page.

sendMessage(text, recipients)

Sends the specified text to the indicated recipients.

API Version

29.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterMessage sendMessage(String text, String recipients)

Parameters

text
Type: String
The text of the message. Cannot be empty or over 10,000 characters.
recipients
Type: String
Up to nine comma-separated IDs of the users receiving the message.

Return Value

Type: ConnectApi.​Chatter​Message

sendMessage(communityId, text, recipients)

Sends the specified text to the indicated recipients across their available communities.

API Version

30.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterMessage sendMessage(String communityId, String text, String recipients)

Parameters

communityId
Type:String
Use either the ID for a community, internal, or null.
text
Type: String
The text of the message. Cannot be empty or over 10,000 characters.
recipients
Type: String
Up to nine comma-separated IDs of users to receive the message.

Return Value

Type: ConnectApi.​Chatter​Message

A Chatter message and all the related metadata.