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(communityId, groupId, userId)

Adds the specified user to the specified group in the specified community as a standard member. To execute this method, the context user must be the group owner or moderator.

API Version

28.0

Requires Chatter

Yes

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.

Return Value

Type: ConnectApi.​GroupMember

addMemberWithRole(communityId, groupId, userId, role)

Adds the specified user with the specified role to the specified group in the specified community. To execute this method, the context user must be the group owner or moderator.

API Version

29.0

Requires Chatter

Yes

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

Return Value

Type: ConnectApi.​GroupMember

addRecord(communityId, groupId, recordId)

Associates a record with a group.

API Version

34.0

Requires Chatter

Yes

Signature

public static ConnectApi.GroupRecord addRecord(String communityId, String groupId, String recordId)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
groupId
Type: String
ID of the group with which to associate the record.
recordId
Type: String
ID of the record to associate with the group.

Return Value

Type: ConnectApi.GroupRecord

createGroup(communityId, groupInput)

Creates a group.

API Version

29.0

Requires Chatter

Yes

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
The properties of the group.

deleteMember(communityId, membershipId)

Deletes the specified group membership.

API Version

28.0

Requires Chatter

Yes

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(communityId, groupId)

Deletes the photo of the specified group.

API Version

28.0

Requires Chatter

Yes

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.

getAnnouncements(communityId, groupId)

Gets the first page of announcements in a group. An announcement displays in a designated location in the Salesforce UI until 11:59 p.m. on its expiration date, unless it’s deleted or replaced by another announcement.

API Version

31.0

Requires Chatter

Yes

Signature

public static ConnectApi.AnnouncementPage getAnnouncements(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.AnnouncementPage

Usage

To post an announcement, call postAnnouncement(communityId, groupId, announcement).

To get information about a specific announcement, update the expiration date of an announcement, or delete an announcement, use the methods of the ConnectApi.Announcements class.

getAnnouncements(communityId, groupId, pageParam, pageSize)

Gets the specified page of announcements in a group. You can also specify the page size. An announcement displays in a designated location in the Salesforce UI until 11:59 p.m. on its expiration date, unless it’s deleted or replaced by another announcement.

API Version

31.0

Requires Chatter

Yes

Signature

public static ConnectApi.AnnouncementPage getAnnouncements(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
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.AnnouncementPage

Usage

To post an announcement, call postAnnouncement(communityId, groupId, announcement).

To get information about a specific announcement, update the expiration date of an announcement, or delete an announcement, use the methods of the ConnectApi.Announcements class.

getGroup(communityId, groupId)

Returns information about the specified group.

API Version

28.0

Available to Guest Users

31.0

Requires Chatter

Yes

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.

getGroupBatch(communityId, groupIds)

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

API Version

31.0

Requires Chatter

Yes

Signature

public static ConnectApi.BatchResult[] getGroupBatch(String communityId, List<String> groupIds)

Parameters

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

Return Value

Type: BatchResult[]

The BatchResult.getResult() method returns a ConnectApi.ChatterGroup object.

Example

// Create a list of groups.
ConnectApi.ChatterGroupPage groupPage = ConnectApi.ChatterGroups.getGroups(null);

// Create a list of group IDs.
List<String> groupIds = new List<String>();
for (ConnectApi.ChatterGroup aGroup : groupPage.groups){
    groupIds.add(aGroup.id); 
}

// Get info about all the groups in the list.
ConnectApi.BatchResult[] batchResults = ConnectApi.ChatterGroups.getGroupBatch(null, groupIds);
    
for (ConnectApi.BatchResult batchResult : batchResults) {
    if (batchResult.isSuccess()) {
        // Operation was successful. 
        // Print the number of members in each group.
        ConnectApi.ChatterGroup aGroup;
        if(batchResult.getResult() instanceof ConnectApi.ChatterGroup) {
           aGroup = (ConnectApi.ChatterGroup) batchResult.getResult();
        }
        System.debug('SUCCESS');
        System.debug(aGroup.memberCount);
    }
    else {
        // Operation failed. Print errors.
        System.debug('FAILURE');
        System.debug(batchResult.getErrorMessage());
    }
}

getGroupMembershipRequest(communityId, requestId)

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

API Version

28.0

Requires Chatter

Yes

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(communityId, groupId)

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

API Version

28.0

Requires Chatter

Yes

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(communityId, groupId, status)

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

API Version

28.0

Requires Chatter

Yes

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(communityId)

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

API Version

28.0

Available to Guest Users

31.0

Requires Chatter

Yes

Signature

public static ConnectApi.ChatterGroupPage getGroups(String communityId)

Parameters

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

getGroups(communityId, pageParam, pageSize)

Returns the specified page of information about all groups.

API Version

28.0

Available to Guest Users

31.0

Requires Chatter

Yes

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 feed items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.

getGroups(communityId, pageParam, pageSize, archiveStatus)

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

API Version

29.0

Available to Guest Users

31.0

Requires Chatter

Yes

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 feed items per page. Valid values are from 1 through 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(communityId, membershipId)

Returns information about the specified group member.

API Version

28.0

Requires Chatter

Yes

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.

Return Value

Type: ConnectApi.​GroupMember

getMembers(communityId, groupId)

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

Requires Chatter

Yes

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(communityId, groupId, pageParam, pageSize)

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

API Version

28.0

Requires Chatter

Yes

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.

getMembershipBatch(communityId, membershipIds)

Gets information about the specified list of group memberships. Returns a list of BatchResult objects containing ConnectApi.GroupMember objects. Returns errors embedded in the results for group memberships that couldn’t be accessed.

API Version

31.0

Requires Chatter

Yes

Signature

public static ConnectApi.BatchResult[] getMembershipBatch(String communityId, List<String> membershipIds)

Parameters

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

Return Value

Type: BatchResult[]

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

Example

// Get members of a group.
ConnectApi.GroupMemberPage membersPage = ConnectApi.ChatterGroups.getMembers(null, '0F9D00000000oOT');

// Create a list of membership IDs.
List<String> membersList = new List<String>();
for (ConnectApi.GroupMember groupMember : membersPage.members){
    membersList.add(groupMember.id); 
}

// Get info about all group memberships in the list.
ConnectApi.BatchResult[] batchResults = ConnectApi.ChatterGroups.getMembershipBatch(null, membersList);

for (ConnectApi.BatchResult batchResult : batchResults) {
    if (batchResult.isSuccess()) {
        // Operation was successful. 
        // Print the first name of each member.
        ConnectApi.GroupMember groupMember;
        if(batchResult.getResult() instanceof ConnectApi.GroupMember) {
            groupMember = (ConnectApi.GroupMember) batchResult.getResult();
        }
        System.debug('SUCCESS');
        System.debug(groupMember.user.firstName);
    }
    else {
        // Operation failed. Print errors.
        System.debug('FAILURE');
        System.debug(batchResult.getErrorMessage());
    }
}

getMyChatterSettings(communityId, groupId)

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

API Version

28.0

Requires Chatter

Yes

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(communityId, groupId)

Returns information about the photo for the specified group.

API Version

28.0

Requires Chatter

Yes

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

getRecord(communityId, groupRecordId)

Returns information about a record associated with a group.

API Version

34.0

Requires Chatter

Yes

Signature

public static ConnectApi.GroupRecord getRecord(String communityId, String groupRecordId)

Parameters

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

Return Value

Type: ConnectApi.GroupRecord

getRecords(communityId, groupId)

Returns the first page of records associated with the specified group. The page contains the default number of items.

API Version

33.0

Requires Chatter

Yes

Signature

public static ConnectApi.GroupRecordPage getRecords(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.​GroupRecordPage

getRecords(communityId, groupId, pageParam, pageSize)

Returns the specified page from the list of records associated with a group.

API Version

33.0

Requires Chatter

Yes

Signature

public static ConnectApi.GroupRecordPage getRecords(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.

Return Value

Type: ConnectApi.​GroupRecordPage

postAnnouncement(communityId, groupId, announcement)

Posts an announcement to the group. An announcement displays in a designated location in the Salesforce UI until 11:59 p.m. on its expiration date, unless it’s deleted or replaced by another announcement.

API Version

31.0

Requires Chatter

Yes

Signature

public static ConnectApi.Announcement postAnnouncement(String communityId, String groupId, ConnectApi.AnnouncementInput announcement)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
groupId
Type: String
The ID for a group.
announcement
Type: ConnectApi.AnnouncementInput
A ConnectApi.AnnouncementInput object.

Return Value

Type: ConnectApi.Announcement

Usage

Use an announcement to highlight information. Users can discuss, like, and post comments on announcements in the group feed. Group members receive an email notification when you post an announcement, same as for other posts, depending on their selected group email notification frequency. Deleting the feed post deletes the announcement.

To get information about all the announcements in a group, call getAnnouncements(communityId, groupId) or getAnnouncements(communityId, groupId, pageParam, pageSize).

To get information about a specific announcement, update the expiration date of an announcement, or delete an announcement, use the methods of the ConnectApi.Announcements class.

removeRecord(communityId, groupRecordId)

Removes the association of a record with a group.

API Version

34.0

Requires Chatter

Yes

Signature

public static Void removeRecord(String communityId, String groupRecordId)

Parameters

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

Return Value

Type: Void

requestGroupMembership(communityId, groupId)

Requests membership in a private group for the context user.

API Version

28.0

Requires Chatter

Yes

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.

String communityId = null;
ID groupId = '0F9x00000000hAZ';

ConnectApi.GroupMembershipRequest membershipRequest = ConnectApi.ChatterGroups.requestGroupMembership(communityId, groupId);

searchGroups(communityId, q)

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

API Version

28.0

Available to Guest Users

31.0

Requires Chatter

Yes

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.

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.

searchGroups(communityId, q, pageParam, pageSize)

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

API Version

28.0

Available to Guest Users

31.0

Requires Chatter

Yes

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 feed items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.

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.

searchGroups(communityId, q, archiveStatus, pageParam, pageSize)

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

API Version

29.0

Available to Guest Users

31.0

Requires Chatter

Yes

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 feed items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.

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, groupId, fileId, versionNumber)

Sets the group photo to an already uploaded file.

API Version

28.0

Requires Chatter

Yes

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 key prefix must be 069, and the file must be an image that is smaller than 2 GB.
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

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 GB.

String communityId = null;
ID groupId = '0F9x00000000hAK';
ID fileId = '069x00000001Ion';

// Set photo
ConnectApi.Photo photo = ConnectApi.ChatterGroups.setPhoto(communityId, groupId, fileId, null);

setPhoto(communityId, groupId, fileUpload)

Sets the group photo to the specified blob..

API Version

28.0

Requires Chatter

Yes

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
A file to use as the photo. The content type must be usable as an image.

Return Value

Type: ConnectApi.Photo

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.

String communityId = null;
ID groupId = '0F9x00000000hAP';
ID photoId = '069x00000001Ioo';

// Set photo
List<ContentVersion> groupPhoto = [Select c.VersionData From ContentVersion c where ContentDocumentId=:photoId];
ConnectApi.BinaryInput binary = new ConnectApi.BinaryInput(groupPhoto.get(0).VersionData, 'image/png', 'image.png');
ConnectApi.Photo photo = ConnectApi.ChatterGroups.setPhoto(communityId, groupId, binary);

setPhotoWithAttributes(communityId, groupId, photo)

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

API Version

29.0

Requires Chatter

Yes

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
A ConnectApi.PhotoInput object that specifies the ID and version of the file, and how to crop the file.

Return Value

Type: ConnectApi.Photo

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(communityId, groupId, photo, fileUpload)

Sets and crops a binary input as the group photo.

API Version

29.0

Requires Chatter

Yes

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
A ConnectApi.PhotoInput object that specifies how to crop the file specified in fileUpload.
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

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.

updateGroup(communityId, groupId, groupInput)

Update the settings of a group.

API Version

28.0

Requires Chatter

Yes

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
A ConnectApi.ChatterGroupInput object.

Return Value

Type: ConnectApi.ChatterGroup

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:
String groupId = '0F9D00000000qSz';
String communityId = null;

ConnectApi.Chatter​​GroupInput groupInput = new ConnectApi.Chatter​​GroupInput();
groupInput.isArchived = true;

ConnectApi.ChatterGroups.updateGroup(communityId, groupId, groupInput);

updateGroupMember(communityId, membershipId, role)

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

Requires Chatter

Yes

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

updateMyChatterSettings(communityId, groupId, emailFrequency)

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

API Version

28.0

Requires Chatter

Yes

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(communityId, userId, defaultGroupEmailFrequency).

updateRequestStatus(communityId, requestId, status)

Updates a request to join a private group.

API Version

28.0

Requires Chatter

Yes

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.

String communityId = null;
ID groupId = '0F9x00000000hAZ';
String requestId = '0I5x000000001snCAA';

ConnectApi.GroupMembershipRequest membershipRequestRep = ConnectApi.ChatterGroups.updateRequestStatus(communityId, requestId, 
ConnectApi.GroupMembershipRequestStatus.Accepted);

updateRequestStatus(communityId, requestId, status, responseMessage)

Updates a request to join a private group and optionally provides a message when the request is denied.

API Version

35.0

Requires Chatter

Yes

Signature

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

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.GroupMembershipRequestStatus
The status of the request:
  • Accepted
  • Declined

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

responseMessage
Type: String
Provide a message to the user if their membership request is declined. The value of this property is used only when the value of the status property is Declined.

The maximum length is 756 characters.

Usage

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

ChatterGroups Test Methods

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

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

setTestSearchGroups(communityId, q, result)

Registers a ConnectApi.ChatterGroupPage object to be returned when the matching ConnectApi.searchGroups method is called in a test context. 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
The test ConnectApi.ChatterGroupPage object.

Return Value

Type: Void

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

Registers a ConnectApi.ChatterGroupPage object to be returned when the matching ConnectApi.searchGroups method is called in a test context. 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 feed items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.
result
Type: ConnectApi.Chatter​​​GroupPage
The test ConnectApi.ChatterGroupPage object.

Return Value

Type: Void

setTestSearchGroups(communityId, q, archiveStatus, pageParam, pageSize, result)

Registers a ConnectApi.ChatterGroupPage object to be returned when the matching ConnectApi.searchGroups method is called in a test context. 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 feed items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.
result
Type: ConnectApi.Chatter​​​GroupPage
The test ConnectApi.ChatterGroupPage object.

Return Value

Type: Void