ChatterUsers Class

Access information about users, such as followers, subscriptions, files, and groups.

Namespace

ConnectApi

ChatterUsers Methods

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

deletePhoto(communityId, userId)

Deletes the specified user’s photo.

API Version

28.0–34.0

Important

Important

In version 35.0 and later, use ConnectApi.UserProfiles.deletePhoto(communityId, userId)

Signature

public static Void deletePhoto(String communityId, String userId)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for the context user or the keyword me.

Return Value

Type: Void

follow(communityId, userId, subjectId)

Adds the specified userId as a follower to the specified subjectId.

API Version

28.0

Requires Chatter

Yes

Signature

public static ConnectApi.Subscription follow(String communityId, String userId, String subjectId)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for the context user or the keyword me.
subjectId
Type: String
The ID for the subject to follow.

Return Value

Type: ConnectApi.​Subscription

getChatterSettings(communityId, userId)

Returns information about the default Chatter settings for the specified user.

API Version

28.0

Requires Chatter

Yes

Signature

public static ConnectApi.UserChatterSettings getChatterSettings(String communityId, String userId)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for the context user or the keyword me.

getFollowers(communityId, userId)

Returns the first page of followers for the specified user ID. The page contains the default number of items.

API Version

28.0

Available to Guest Users

32.0

Requires Chatter

Yes

Signature

public static ConnectApi.FollowerPage getFollowers(String communityId, String userId)

Parameters

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

Return Value

Type: ConnectApi.​FollowerPage

getFollowers(communityId, userId, pageParam, pageSize)

Returns the specified page of followers for the specified user ID.

API Version

28.0

Available to Guest Users

32.0

Requires Chatter

Yes

Signature

public static ConnectApi.FollowerPage getFollowers(String communityId, String userId, Integer pageParam, Integer pageSize)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for a user.
pageParam
Type: Integer
Specifies the number of the page you want returned. Starts at 0. If you pass in null or 0, the first page is returned.
pageSize
Type: Integer
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.​FollowerPage

getFollowings(communityId, userId)

Returns the first page of information about the followers of the specified user. The page contains the default number of items. This is different than getFollowers, which returns the users that follow the specified user.

API Version

28.0

Available to Guest Users

32.0

Requires Chatter

Yes

Signature

public static ConnectApi.FollowingPage getFollowings(String communityId, String userId)

Parameters

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

Return Value

Type: ConnectApi.​FollowingPage

getFollowings(communityId, userId, pageParam)

Returns the specified page of information about the followers of the specified user. The page contains the default number of items. This is different than getFollowers, which returns the users that follow the specified user.

API Version

28.0

Available to Guest Users

32.0

Requires Chatter

Yes

Signature

public static ConnectApi.FollowingPage getFollowings(String communityId, String userId, Integer pageParam)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for a user.
pageParam
Type: Integer
Specifies the number of the page you want returned. Starts at 0. If you pass in null or 0, the first page is returned.

Return Value

Type: ConnectApi.​FollowingPage

getFollowings(communityId, userId, pageParam, pageSize)

Returns the specific page of information about the followers of the specified user. This is different than getFollowers, which returns the users that follow the specified user.

API Version

28.0

Available to Guest Users

32.0

Requires Chatter

Yes

Signature

public static ConnectApi.FollowingPage getFollowings(String communityId, String userId, Integer pageParam, Integer pageSize)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for a user.
pageParam
Type: Integer
Specifies the number of the page you want returned. Starts at 0. If you pass in null or 0, the first page is returned.
pageSize
Type: Integer
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.​FollowingPage

getFollowings(communityId, userId, filterType)

Returns the first page of information about the specified types of followers of the specified user. The page contains the default number of items. This is different than getFollowers, which returns the users that follow the specified user.

API Version

28.0

Available to Guest Users

32.0

Requires Chatter

Yes

Signature

public static ConnectApi.FollowingPage getFollowings(String communityId, String userId, String filterType)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for a user.
filterType
Type: String
Specifies the key prefix to filter the type of objects returned. A key prefix is the first three characters of the object ID, which specifies the object type. For example, User objects have a prefix of 005 and Group objects have a prefix of 0F9.

Return Value

Type: ConnectApi.​FollowingPage

getFollowings(communityId, userId, filterType, pageParam)

Returns the specified page of information about the specified types of followers of the specified user. The page contains the default number of items. This is different than getFollowers, which returns the users that follow the specified user.

API Version

28.0

Available to Guest Users

32.0

Requires Chatter

Yes

Signature

public static ConnectApi.FollowingPage getFollowings(String communityId, String userId, String filterType, Integer pageParam)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for a user.
filterType
Type: String
Specifies the key prefix to filter the type of objects returned. A key prefix is the first three characters of the object ID, which specifies the object type. For example, User objects have a prefix of 005 and Group objects have a prefix of 0F9.
pageParam
Type: Integer
Specifies the number of the page you want returned. Starts at 0. If you pass in null or 0, the first page is returned.

Return Value

Type: ConnectApi.​FollowingPage

getFollowings(communityId, userId, filterType, pageParam, pageSize)

Returns the specified page of information about the specified types of followers of the specified user. This is different than getFollowers, which returns the users that follow the specified user.

API Version

28.0

Available to Guest Users

32.0

Requires Chatter

Yes

Signature

public static ConnectApi.FollowingPage getFollowings(String communityId, String userId, String filterType, Integer pageParam, Integer pageSize)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for a user.
filterType
Type: String
Specifies the key prefix to filter the type of objects returned. A key prefix is the first three characters of the object ID, which specifies the object type. For example, User objects have a prefix of 005 and Group objects have a prefix of 0F9.
pageParam
Type: Integer
Specifies the number of the page you want returned. Starts at 0. If you pass in null or 0, the first page is returned.
pageSize
Type: Integer
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.​FollowingPage

getGroups(communityId, userId)

Returns the first page of groups the specified user is a member of.

API Version

28.0

Available to Guest Users

32.0

Requires Chatter

Yes

Signature

public static ConnectApi.UserGroupPage getGroups(String communityId, String userId)

Parameters

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

Return Value

Type: ConnectApi.User​​GroupPage

getGroups(communityId, userId, pageParam, pageSize)

Returns the specified page of groups the specified user is a member of.

API Version

28.0

Available to Guest Users

32.0

Requires Chatter

Yes

Signature

public static ConnectApi.UserGroupPage getGroups(String communityId, String userId, Integer pageParam, Integer pageSize)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for a user.
pageParam
Type: Integer
Specifies the number of the page you want returned. Starts at 0. If you pass in null or 0, the first page is returned.
pageSize
Type: Integer
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.User​​GroupPage

getPhoto(communityId, userId)

Returns information about the specified user’s photo.

API Version

28.0–34.0

Important

Important

In version 35.0 and later, use ConnectApi.UserProfiles.getPhoto(communityId, userId).

Available to Guest Users

32.0

Requires Chatter

Yes

Signature

public static ConnectApi.Photo getPhoto(String communityId, String userId)

Parameters

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

Return Value

Type: ConnectApi.Photo

getReputation(communityId, userId)

Returns the reputation of the specified user.

API Version

32.0

Available to Guest Users

32.0

Requires Chatter

Yes

Signature

public static ConnectApi.Reputation getReputation(String communityId, String userId)

Parameters

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

Return Value

Type: ConnectApi.Reputation

getUser(communityId, userId)

Returns information about the specified user.

API Version

28.0

Available to Guest Users

32.0

Requires Chatter

Yes

Signature

public static ConnectApi.UserSummary getUser(String communityId, String userId)

Parameters

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

Return Value

Type: ConnectApi.UserDetail

Usage

If the user is external, the properties that the ConnectApi.UserDetail output class shares with the ConnectApi.UserSummary output class can have non-null values. Other properties are always null.

getUserBatch(communityId, userIds)

Gets information about the specified list of users. Returns a list of BatchResult objects containing ConnectApi.User objects. Returns errors embedded in the results for those users that couldn’t be loaded.

API Version

31.0

Available to Guest Users

32.0

Requires Chatter

Yes

Signature

public static ConnectApi.BatchResult[] getUserBatch(String communityId, List<String> userIds)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userIds
Type: List<String>
A list of up to 500 user IDs.

Return Value

Type: BatchResult[]

The BatchResult getResults() method returns a ConnectApi.User object.

Example

// Get users in an organization.
ConnectApi.UserPage userPage = ConnectApi.ChatterUsers.getUsers(null);

// Create a list of user IDs.
List<String> userList = new List<String>();
for (ConnectApi.User user : userPage.users){
    userList.add(user.id); 
}

// Get info about all users in the list.
ConnectApi.BatchResult[] batchResults = ConnectApi.ChatterUsers.getUserBatch(null, userList);

for (ConnectApi.BatchResult batchResult : batchResults) {
    if (batchResult.isSuccess()) {
        // Operation was successful. 
        // Print each user's username.
        ConnectApi.UserDetail user;
        if(batchResult.getResult() instanceof ConnectApi.UserDetail) {
            user = (ConnectApi.UserDetail) batchResult.getResult();
        }
        System.debug('SUCCESS');
        System.debug(user.username);
    }
    else {
        // Operation failed. Print errors.
        System.debug('FAILURE');
        System.debug(batchResult.getErrorMessage());
    }
}

getUsers(communityId)

Returns the first page of users. The page contains the default number of items.

API Version

28.0

Available to Guest Users

32.0

Requires Chatter

Yes

Signature

public static ConnectApi.UserPage getUsers(String communityId)

Parameters

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

Return Value

Type: ConnectApi.UserPage

getUsers(communityId, pageParam, pageSize)

Returns the specified page of users.

API Version

28.0

Available to Guest Users

32.0

Requires Chatter

Yes

Signature

public static ConnectApi.UserPage getUsers(String communityId, Integer pageParam, Integer pageSize)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
pageParam
Type: Integer
Specifies the number of the page you want returned. Starts at 0. If you pass in null or 0, the first page is returned.
pageSize
Type: Integer
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.UserPage

searchUserGroups(communityId, userId, q)

Returns the first page of groups that match the specified search criteria.

API Version

30.0

Available to Guest Users

32.0

Requires Chatter

Yes

Signature

public static ConnectApi.UserGroupPage searchUserGroups(String communityId, String userId, String q)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for a user.
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.User​​GroupPage

A paginated list of groups the context user is a member of.

searchUserGroups(communityId, userId, q, pageParam, pageSize)

Returns the specified page of users that matches the specified search criteria.

API Version

30.0

Available to Guest Users

32.0

Requires Chatter

Yes

Signature

public static ConnectApi.UserGroupPage searchUserGroups(String communityId, String userId, String q, Integer pageParam, Integer pageSize)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for a user.
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.
pageParam
Type: Integer
Specifies the number of the page you want returned. Starts at 0. If you pass in null or 0, the first page is returned.
pageSize
Type: Integer
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.User​​GroupPage

A paginated list of groups the context user is a member of.

searchUsers(communityId, q)

Returns the first page of users that match the specified search criteria. The page contains the default number of items.

API Version

28.0

Available to Guest Users

32.0

Requires Chatter

Yes

Signature

public static ConnectApi.UserPage searchUsers(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.UserPage

Usage

To test code that uses this method, use the matching set test method (prefix the method name with setTest). Use the set test method with the same parameters or the code throws an exception.

searchUsers(communityId, q, pageParam, pageSize)

Returns the specified page of users that match the specified search criteria.

API Version

28.0

Available to Guest Users

32.0

Requires Chatter

Yes

Signature

public static ConnectApi.UserPage searchUsers(String communityId, String q, Integer pageParam, Integer pageSize)

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.
pageParam
Type: Integer
Specifies the number of the page you want returned. Starts at 0. If you pass in null or 0, the first page is returned.
pageSize
Type: Integer
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.UserPage

Usage

To test code that uses this method, use the matching set test method (prefix the method name with setTest). Use the set test method with the same parameters or the code throws an exception.

searchUsers(communityId, q, searchContextId, pageParam, pageSize)

Returns the specified page of users that match the specified search criteria.

API Version

28.0

Available to Guest Users

32.0

Requires Chatter

Yes

Signature

public static ConnectApi.UserPage searchUsers(String communityId, String q, String searchContextId, Integer pageParam, Integer pageSize)

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.
searchContextId
Type: String
A feed item ID that filters search results for feed @mentions. More useful results are listed first. When you specify this argument, you cannot query more than 500 results and you cannot use wildcards in the search term.
pageParam
Type: Integer
Specifies the number of the page you want returned. Starts at 0. If you pass in null or 0, the first page is returned.
pageSize
Type: Integer
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.UserPage

Usage

To test code that uses this method, use the matching set test method (prefix the method name with setTest). Use the set test method with the same parameters or the code throws an exception.

setPhoto(communityId, userId, fileId, versionNumber)

Sets the user photo to be the specified, already uploaded file.

API Version

28.0–34.0

Requires Chatter

Yes

Signature

public static ConnectApi.Photo setPhoto(String communityId, String userId, String fileId, Integer versionNumber)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for the context user or the keyword me.
fileId
Type: String
ID of a file already uploaded. The file must be an image, and be smaller than 2 GB.
versionNumber
Type: Integer
Version number of the existing file. Specify either an existing version number, or null to get the latest version.

Return Value

Type: ConnectApi.Photo

Usage

Photos are processed asynchronously and may not be visible right away.

setPhoto(communityId, userId, fileUpload)

Sets the provided blob to be the photo for the specified user. The content type must be usable as an image.

API Version

28.0–34.0

Requires Chatter

Yes

Signature

public static ConnectApi.Photo setPhoto(String communityId, String userId, ConnectApi.BinaryInput fileUpload)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for the context user or the keyword me.
fileUpload
Type: ConnectApi.Binary​​Input
A file to use as the photo. The content type must be usable as an image.

Return Value

Type: ConnectApi.Photo

Usage

Photos are processed asynchronously and may not be visible right away.

setPhotoWithAttributes(communityId, userId, photo)

Sets and crops the existing file as the photo for the specified user. The content type must be usable as an image.

API Version

29.0–34.0

Requires Chatter

Yes

Signature

public static ConnectApi.Photo setPhotoWithAttributes(String communityId, String userId, ConnectApi.PhotoInput photo)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for the context user or the keyword me.
photo
Type: ConnectApi.PhotoInput
A ConnectApi.PhotoInput object specifying the file ID, version number, and cropping parameters.

Return Value

Type: ConnectApi.Photo

Usage

Photos are processed asynchronously and may not be visible right away.

setPhotoWithAttributes(communityId, userId, photo, fileUpload)

Sets and crops the provided blob as the photo for the specified user. The content type must be usable as an image.

API Version

29.0–34.0

Requires Chatter

Yes

Signature

public static ConnectApi.Photo setPhotoWithAttributes(String communityId, String userId, ConnectApi.PhotoInput photo, ConnectApi.BinaryInput fileUpload)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for the context user or the keyword me.
photo
Type: ConnectApi.PhotoInput
A ConnectApi.PhotoInput object specifying the cropping parameters.
fileUpload
Type: ConnectApi.Binary​​Input
A file to use as the photo. The content type must be usable as an image.

Return Value

Type: ConnectApi.Photo

Usage

Photos are processed asynchronously and may not be visible right away.

updateChatterSettings(communityId, userId, defaultGroupEmailFrequency)

Updates the default Chatter settings for the specified user.

API Version

28.0

Requires Chatter

Yes

Signature

public static ConnectApi.UserChatterSettings updateChatterSettings(String communityId, String userId, ConnectApi.GroupEmailFrequency defaultGroupEmailFrequency)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for the context user or the keyword me.
defaultGroupEmailFrequency
Type: ConnectApi.​GroupEmail​Frequency
defaultGroupEmailFrequencySpecifies the frequency with which a user receives email from a group. Values:
  • EachPost
  • DailyDigest
  • WeeklyDigest
  • Never
  • UseDefault

Don’t pass the value UseDefault for the defaultGroupEmailFrequency parameter because calling updateChatterSettings sets the default value.

updateUser(communityId, userId, userInput)

Updates the “About Me” section for a user.

API Version

29.0

Requires Chatter

Yes

Signature

public static ConnectApi.UserDetail updateUser(String communityId, String userId, ConnectApi.UserInput userInput)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for the context user or the keyword me.
userInput
Type: ConnectApi.UserInput
Specifies the updated information.

Return Value

Type: ConnectApi.​User​Detail

ChatterUsers Test Methods

The following are the test methods for ChatterUsers. All methods are static.

For information about using these methods to test your ConnectApi code, see Testing ConnectApi Code.

setTestSearchUsers(communityId, q, result)

Registers a ConnectApi.UserPage object to be returned when the matching ConnectApi.searchUsers method is called in a test context. Use the method with the same parameters or you receive an exception.

API Version

28.0

Signature

public static Void setTestSearchUsers(String communityId, String q, ConnectApi.UserPage result)

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.
result
Type: ConnectApi.UserPage
The object containing test data.

Return Value

Type: Void

setTestSearchUsers(communityId, q, pageParam, pageSize, result)

Registers a ConnectApi.UserPage object to be returned when the matching ConnectApi.searchUsers method is called in a test context. Use the method with the same parameters or you receive an exception.

API Version

28.0

Signature

public static Void setTestSearchUsers(String communityId, String q, Integer pageParam, Integer pageSize, ConnectApi.UserPage result)

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.
pageParam
Type: Integer
Specifies the number of the page you want returned. Starts at 0. If you pass in null or 0, the first page is returned.
pageSize
Type: Integer
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.
result
Type: ConnectApi.UserPage
The object containing test data.

Return Value

Type: Void

setTestSearchUsers(communityId, q, searchContextId, pageParam, pageSize, result)

Registers a ConnectApi.UserPage object to be returned when the matching ConnectApi.searchUsers method is called in a test context. Use the method with the same parameters or you receive an exception.

API Version

28.0

Signature

public static Void setTestSearchUsers(String communityId, String q, String searchContextId, Integer pageParam, Integer pageSize, ConnectApi.UserPage result)

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.
searchContextId
Type: String
A feed item ID that filters search results for feed @mentions. More useful results are listed first. When you specify this argument, you cannot query more than 500 results and you cannot use wildcards in the search term.
pageParam
Type: Integer
Specifies the number of the page you want returned. Starts at 0. If you pass in null or 0, the first page is returned.
pageSize
Type: Integer
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.
result
Type: ConnectApi.UserPage
The object containing test data.

Return Value

Type: Void