Newer Version Available

This content describes an older version of this product. View Latest

ChatterGroups Class

Information about groups, such as the group’s members, photo, and the groups the specified user is a member of. Add members to a group, remove members, and change the group photo.

Namespace

ConnectApi

ChatterGroups Methods

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

addMember(String, String, String)

Adds the specified user to the specified group in the specified community as a standard member.

API Version

28.0

Signature

public static ConnectApi.GroupMember addMember(String communityId, String groupId, String userId)

Parameters

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

addMemberWithRole(String, String, String, ConnectApi.GroupMembershipType)

Adds the specified user with the specified role to the specified group in the specified community.

API Version

29.0

Signature

public static ConnectApi.GroupMember addMemberWithRole(String communityId, String groupId, String userId, ConnectApi.GroupMembershipType role)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
groupId
Type: String
The ID for a group.
userId
Type: String
The ID for a user.
role
Type: ConnectApi.GroupMembershipType
The group membership type. One of these values:
  • GroupManager
  • StandardMember

createGroup(String, ConnectApi.ChatterGroupInput)

Creates a group.

API Version

29.0

Signature

public static ConnectApi.ChatterGroupDetail createGroup(String, communityId, ConnectApi.ChatterGroupInput groupInput)

Parameters

communityId
Type: String,
Use either the ID for a community, internal, or null.
groupInput
Type: ConnectApi.Chatter​​GroupInput Class
The properties of the group.

deleteMember(String, String)

Deletes the specified group membership.

API Version

28.0

Signature

public static Void deleteMember(String communityId, String membershipId)

Parameters

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

Return Value

Type: Void

Usage

This method is only successful when the context user is the group manager or owner, or has “Modify All Data” permission.

deletePhoto(String, String)

Deletes the photo of the specified group.

API Version

28.0

Signature

public static Void deletePhoto(String communityId, String groupId)

Parameters

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

Return Value

Type: Void

Usage

This method is only successful when the context user is the group manager or owner, or has “Modify All Data” permission.

getGroup(String, String)

Returns information about the specified group.

API Version

28.0

Signature

public static ConnectApi.ChatterGroupDetail getGroup(String communityId, String groupId)

Parameters

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

getGroupMembershipRequest(String, String)

Returns information about the specified request to join a private group.

API Version

28.0

Signature

public static ConnectApi.GroupMembershipRequest getGroupMembershipRequest(String communityId, String requestId)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
requestId
Type: String
The ID of a request to join a private group.

Usage

This method is only successful when the context user is the group manager or owner, or has “Modify All Data” permission.

getGroupMembershipRequests(String, String)

Returns information about every request to join the specified private group.

API Version

28.0

Signature

public static ConnectApi.GroupMembershipRequests getGroupMembershipRequests(String communityId, String groupId)

Parameters

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

Usage

This method is only successful when the context user is the group manager or owner, or has “Modify All Data” permission.

getGroupMembershipRequests(String, String, ConnectApi.GroupMembershipRequestStatus)

Returns information about every request to join the specified private group that has a specified status.

API Version

28.0

Signature

public static ConnectApi.GroupMembershipRequests getGroupMembershipRequests(String communityId, String groupId, ConnectApi.GroupMembershipRequestStatus status)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
groupId
Type: String
The ID for a group.
status
Type: ConnectApi.​​​GroupMembership​​​RequestStatus
statusThe status of a request to join a private group.
  • Accepted
  • Declined
  • Pending

Usage

This method is only successful when the context user is the group manager or owner, or has “Modify All Data” permission.

getGroups(String)

Returns the first page of all the groups. The page contains the default number of items.

API Version

28.0

Signature

public static ConnectApi.ChatterGroupPage getGroups(String communityId)

Parameters

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

getGroups(String, Integer, Integer)

Returns the specified page of information about all groups.

API Version

28.0

Signature

public static ConnectApi.ChatterGroupPage getGroups(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 items per page. Valid values are between 1 and 100. If you pass in null, the default size is 25.

getGroups(String, Integer, Integer, ConnectApi.GroupArchiveStatus)

Returns the specified page of information about a set of groups with a specified group archive status.

API Version

29.0

Signature

public static ConnectApi.ChatterGroupPage getGroups(String communityId, Integer pageParam, Integer pageSize, ConnectApi.GroupArchiveStatus archiveStatus)

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 items per page. Valid values are between 1 and 100. If you pass in null, the default size is 25.
archiveStatus
Type: ConnectApi.GroupArchiveStatus
Specifies a set of groups based on whether the groups are archived or not.
  • All—All groups, including groups that are archived and groups that are not archived.
  • Archived—Only groups that are archived.
  • NotArchived—Only groups that are not archived.
If you pass in null, the default value is All.

getMember(String, String)

Returns information about the specified group member.

API Version

28.0

Signature

public static ConnectApi.GroupMember getMember(String communityId, String membershipId)

Parameters

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

getMembers(String, String)

Returns the first page of information about all members of the specified group. The page contains the default number of items.

API Version

28.0

Signature

public static ConnectApi.GroupMemberPage getMembers(String communityId, String groupId)

Parameters

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

getMembers(String, String, Integer, Integer)

Returns the specified page of information about all members of the specified group.

API Version

28.0

Signature

public static ConnectApi.GroupMemberPage getMembers(String communityId, String groupId, Integer pageParam, Integer pageSize)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
groupId
Type: String
The ID for a group.
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
The number of items per page. Valid values are between 1 and 1000. If you pass null, pageSize is 25.

getMyChatterSettings(String, String)

Returns the context user’s Chatter settings for the specified group.

API Version

28.0

Signature

public static ConnectApi.GroupChatterSettings getMyChatterSettings(String communityId, String groupId)

Parameters

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

getPhoto(String, String)

Returns information about the photo for the specified group.

API Version

28.0

Signature

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

Parameters

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

Return Value

Type: ConnectApi.Photo Class

requestGroupMembership(String, String)

Requests membership in a private group for the context user.

API Version

28.0

Signature

public static ConnectApi.GroupMembershipRequest requestGroupMembership(String communityId, String groupId)

Parameters

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

Sample: Requesting to Join a Private Group

This sample code calls ConnectApi.ChatterGroups.requestGroupMembership to request to join a private group.

1String communityId = null;
2ID groupId = '0F9x00000000hAZ';
3
4ConnectApi.GroupMembershipRequest membershipRequest = ConnectApi.ChatterGroups.requestGroupMembership(communityId, groupId);

searchGroups(String, String)

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

API Version

28.0

Signature

public static ConnectApi.ChatterGroupPage searchGroups(String communityId, String q)

Parameters

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

searchGroups(String, String, Integer, Integer)

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

API Version

28.0

Signature

public static ConnectApi.ChatterGroupPage searchGroups(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
qSpecifies the string to search. The search string must contain at least two characters, not including wildcards. See Wildcards. Can be specified as 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 items per page. Valid values are between 1 and 100. If you pass in null, the default size is 25.

searchGroups(String, String, ConnectApi.GroupArchiveStatus, Integer, Integer)

Returns the specified page of groups that match the specified search criteria and that have the specified archive status.

API Version

29.0

Signature

public static ConnectApi.ChatterGroupPage searchGroups(String communityId, String q, ConnectApi.GroupArchiveStatus archiveStatus, Integer pageParam, Integer pageSize)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
q
Type: String
qSpecifies the string to search. The search string must contain at least two characters, not including wildcards. See Wildcards. Can be specified as null.
archiveStatus
Type: ConnectApi.GroupArchiveStatus
archiveStatus Specifies a set of groups based on whether the groups are archived or not.
  • All—All groups, including groups that are archived and groups that are not archived.
  • Archived—Only groups that are archived.
  • NotArchived—Only groups that are not archived.
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 items per page. Valid values are between 1 and 100. If you pass in null, the default size is 25.

setPhoto(String, String, String, Integer)

Sets the group photo to an already uploaded file. The key prefix must be 069 and the file size must be less than 2 MB.

API Version

28.0

Signature

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

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
groupId
Type: String
The ID for a group.
fileId
Type: String
ID of a file already uploaded. The file must be an image smaller than 2 MB.
versionNumber
Type: Integer
Version number of the existing file. Specify either an existing version number or, to get the latest version, specify null.

Return Value

Type: ConnectApi.Photo Class

Usage

This method is only successful when the context user is the group manager or owner, or has “Modify All Data” permission.

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

Sample: Updating a Group Photo with an Existing File

When a group is created, it doesn’t have a group photo. You can set an existing photo that has already been uploaded to Salesforce as the group photo. The key prefix must be 069 and the file size must be less than 2 MB.

1String communityId = null;
2ID groupId = '0F9x00000000hAK';
3ID fileId = '069x00000001Ion';
4
5// Set photo
6ConnectApi.Photo photo = ConnectApi.ChatterGroups.setPhoto(communityId, groupId, fileId, null);

setPhoto(String, String, ConnectApi.BinaryInput)

Sets the group photo to the specified blob..

API Version

28.0

Signature

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

Parameters

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

Return Value

Type: ConnectApi.Photo Class

Usage

This method is only successful when the context user is the group manager or owner, or has “Modify All Data” permission.

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

Sample: Uploading a New File and Using it as a Group Photo

When a group is created, it doesn’t have a group photo. You can upload a photo and set it as the group photo.

1String communityId = null;
2ID groupId = '0F9x00000000hAP';
3ID photoId = '069x00000001Ioo';
4
5// Set photo
6List<ContentVersion> groupPhoto = [Select c.VersionData From ContentVersion c where ContentDocumentId=:photoId];
7ConnectApi.BinaryInput binary = new ConnectApi.BinaryInput(groupPhoto.get(0).VersionData, 'image/png', 'image.png');
8ConnectApi.Photo photo = ConnectApi.ChatterGroups.setPhoto(communityId, groupId, binary);

setPhotoWithAttributes(String, String, ConnectApi.PhotoInput)

Sets and crops an already uploaded file as the group photo.

API Version

29.0

Signature

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

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
groupId
Type: String
The ID for a group.
photo
Type: ConnectApi.PhotoInput Class
A ConnectApi.PhotoInput object that specifies the ID and version of the file, and how to crop the file.

Return Value

Type: ConnectApi.Photo Class

Usage

This method is only successful when the context user is the group manager or owner, or has “Modify All Data” permission.

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

setPhotoWithAttributes(String, String, ConnectApi.PhotoInput, ConnectApi.BinaryInput)

Sets and crops a binary input as the group photo.

API Version

29.0

Signature

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

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
groupId
Type: String
The ID for a group.
photo
Type: ConnectApi.PhotoInput Class
A ConnectApi.PhotoInput object that specifies how to crop the file specified in fileUpload.
fileUpload
Type: ConnectApi.Binary​​Input Class
A file to use as the photo. The content type must be usable as an image.

Return Value

Type: ConnectApi.Photo Class

Usage

This method is only successful when the context user is the group manager or owner, or has “Modify All Data” permission.

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

setTestSearchGroups(String, String, ConnectApi.ChatterGroupPage)

Registers a ConnectApi.ChatterGroupPage object to be returned when the matching ConnectApi.searchGroups method is called in a test context. You must use the test method with the same parameters or you receive an exception.

API Version

29.0

Signature

public static Void setTestSearchGroups(String communityId, String q, ConnectApi.ChatterGroupPage result)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
q
Type: String
qSpecifies the string to search. The search string must contain at least two characters, not including wildcards. See Wildcards. Can be specified as null.
result
Type: ConnectApi.Chatter​​​GroupPage Class
The test ConnectApi.ChatterGroupPage object.

Return Value

Type: Void

setTestSearchGroups(String, String, Integer, Integer, ConnectApi.ChatterGroupPage)

Registers a ConnectApi.ChatterGroupPage object to be returned when the matching ConnectApi.searchGroups method is called in a test context. You must use the test method with the same parameters or you receive an exception.

API Version

28.0

Signature

public static Void setTestSearchGroups(String communityId, String q, Integer pageParam, Integer pageSize, ConnectApi.ChatterGroupPage result)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
q
Type: String
qSpecifies the string to search. The search string must contain at least two characters, not including wildcards. See Wildcards. Can be specified as 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 items per page. Valid values are between 1 and 100. If you pass in null, the default size is 25.
result
Type: ConnectApi.Chatter​​​GroupPage Class
The test ConnectApi.ChatterGroupPage object.

Return Value

Type: Void

setTestSearchGroups(String, String, ConnectApi.GroupArchiveStatus, Integer, Integer, ConnectApi.ChatterGroupPage)

Registers a ConnectApi.ChatterGroupPage object to be returned when the matching ConnectApi.searchGroups method is called in a test context. You must use the test method with the same parameters or you receive an exception.

API Version

29.0

Signature

public static Void setTestSearchGroups(String communityId, String q, ConnectApi.GroupArchiveStatus, archiveStatus, Integer pageParam, Integer pageSize, ConnectApi.ChatterGroupPage result)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
q
Type: String
qSpecifies the string to search. The search string must contain at least two characters, not including wildcards. See Wildcards. Can be specified as null.
archiveStatus
Type: ConnectApi.GroupArchiveStatus
archiveStatusSpecifies a set of groups based on whether the groups are archived or not.
  • All—All groups, including groups that are archived and groups that are not archived.
  • Archived—Only groups that are archived.
  • NotArchived—Only groups that are not archived.
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 items per page. Valid values are between 1 and 100. If you pass in null, the default size is 25.
result
Type: ConnectApi.Chatter​​​GroupPage Class
The test ConnectApi.ChatterGroupPage object.

Return Value

Type: Void

updateGroup(String, String, ConnectApi.ChatterGroupInput)

Update the settings of a group.

API Version

28.0

Signature

public static ConnectApi.ChatterGroup updateGroup(String communityId, String groupId, ConnectApi.ChatterGroupInput groupInput)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
groupId
Type: String
The ID for a group.
groupInput
Type: ConnectApi.Chatter​​GroupInput Class
A ConnectApi.ChatterGroupInput object.

Return Value

Type: ConnectApi.ChatterGroup Class

Usage

This method is only successful when the context user is the group manager or owner, or has “Modify All Data” permission. Use this method to update any settings in the ConnectApi.ChatterGroupInput class. These settings include the group title and text in the “Information” section, whether the group is public or private, and whether the group is archived.

Example

This example archives a group:
1swfobject.registerObject("clippy.codeblock-3", "9");String groupId = '0F9D00000000qSz';
2String communityId = null;
3
4ConnectApi.Chatter​​GroupInput groupInput = new ConnectApi.Chatter​​GroupInput();
5groupInput.isArchived = true;
6
7ConnectApi.ChatterGroups.updateGroup(communityId, groupId, groupInput);

updateGroupMember(String, String, ConnectApi.GroupMembershipType)

Updates the specified group membership with the specified role in the specified community. This method is only successful when the context user is the group manager or owner, or has “Modify All Data” permission.

API Version

29.0

Signature

public static ConnectApi.ChatterGroup updateGroupMember(String communityId, String membershipId, ConnectApi.GroupMembershipType role)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
membershipId
Type: String
The ID for a membership.
role
Type: ConnectApi.GroupMembershipType
The group membership type. One of these values:
  • GroupManager
  • StandardMember

Return Value

Type: ConnectApi.ChatterGroup Class

updateMyChatterSettings(String, String, ConnectApi.GroupEmailFrequency)

Updates the context user’s Chatter settings for the specified group.

API Version

28.0

Signature

public static ConnectApi.GroupChatterSettings updateMyChatterSettings(String communityId, String groupId, ConnectApi.GroupEmailFrequency emailFrequency)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
groupId
Type: String
The ID for a group.
emailFrequency
Type: ConnectApi.​​​GroupEmail​​​Frequency
emailFrequencySpecifies the frequency with which a user receives email from a group.
  • EachPost
  • DailyDigest
  • WeeklyDigest
  • Never
  • UseDefault

The value UseDefault uses the value set in a call to updateChatterSettings(String, String, ConnectApi.GroupEmailFrequency).

updateRequestStatus(String, String, ConnectApi.GroupMembershipRequestStatus)

Updates a request to join a private group.

API Version

28.0

Signature

public static ConnectApi.GroupMembershipRequest updateRequestStatus(String communityId, String requestId, ConnectApi.GroupMembershipRequestStatus status)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
requestId
Type: String
The ID for a request to join a private group.
status
Type: ConnectApi.​​​GroupMembership​​​RequestStatus
The status of the request:
  • Accepted
  • Declined

The Pending value of the enum is not valid in this method.

Usage

This method is only successful when the context user is the group manager or owner, or has “Modify All Data” permission.

Sample: Accepting or Declining a Request to Join a Private Group

This sample code calls ConnectApi.ChatterGroups.updateRequestStatus and passes it the membership request ID and an ConnectApi.GroupMembershipRequestStatus.Accepted status. You can also pass ConnectApi.GroupMembershipRequestStatus.Declined.

1String communityId = null;
2ID groupId = '0F9x00000000hAZ';
3String requestId = '0I5x000000001snCAA';
4
5ConnectApi.GroupMembershipRequest membershipRequestRep = ConnectApi.ChatterGroups.updateRequestStatus(communityId, requestId, 
6ConnectApi.GroupMembershipRequestStatus.Accepted);