The following are methods for ChatterGroups. All methods are static.
28.0
Yes
public static ConnectApi.GroupMember addMember(String communityId, String groupId, String userId)
Type: ConnectApi.GroupMember
29.0
Yes
public static ConnectApi.GroupMember addMemberWithRole(String communityId, String groupId, String userId, ConnectApi.GroupMembershipType role)
Type: ConnectApi.GroupMember
34.0
Yes
public static ConnectApi.GroupRecord addRecord(String communityId, String groupId, String recordId)
Type: ConnectApi.GroupRecord
29.0
Yes
public static ConnectApi.ChatterGroupDetail createGroup(String, communityId, ConnectApi.ChatterGroupInput groupInput)
36.0
Yes
public static Void deleteBannerPhoto(String communityId, String groupId)
Type: Void
28.0
Yes
public static Void deleteMember(String communityId, String membershipId)
Type: Void
This method is successful only when the context user is the group manager or owner, or has Modify All Data permission.
28.0
Yes
public static Void deletePhoto(String communityId, String groupId)
Type: Void
This method is only successful when the context user is the group manager or owner, or has Modify All Data permission.
31.0
Yes
public static ConnectApi.AnnouncementPage getAnnouncements(String communityId, String groupId)
To post an announcement, get information about an announcement, update the expiration date of an announcement, or delete an announcement, use the methods of the ConnectApi.Announcements class.
31.0
Yes
public static ConnectApi.AnnouncementPage getAnnouncements(String communityId, String groupId, Integer pageParam, Integer pageSize)
To post an announcement, get information about an announcement, update the expiration date of an announcement, or delete an announcement, use the methods of the ConnectApi.Announcements class.
36.0
Yes
public static ConnectApi.BannerPhoto getBannerPhoto(String communityId, String groupId)
Type: ConnectApi.BannerPhoto
28.0
31.0
Yes
public static ConnectApi.ChatterGroupDetail getGroup(String communityId, String groupId)
31.0
Yes
public static ConnectApi.BatchResult[] getGroupBatch(String communityId, List<String> groupIds)
Type: BatchResult[]
The BatchResult.getResult() method returns a ConnectApi.ChatterGroup object.
// 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()); } }
28.0
Yes
public static ConnectApi.GroupMembershipRequest getGroupMembershipRequest(String communityId, String requestId)
This method is successful only when the context user is the group manager or owner, or has Modify All Data permission.
28.0
Yes
public static ConnectApi.GroupMembershipRequests getGroupMembershipRequests(String communityId, String groupId)
This method is successful only when the context user is the group manager or owner, or has Modify All Data permission.
28.0
Yes
public static ConnectApi.GroupMembershipRequests getGroupMembershipRequests(String communityId, String groupId, ConnectApi.GroupMembershipRequestStatus status)
This method is successful only when the context user is the group manager or owner, or has Modify All Data permission.
28.0
31.0
Yes
public static ConnectApi.ChatterGroupPage getGroups(String communityId)
28.0
31.0
Yes
public static ConnectApi.ChatterGroupPage getGroups(String communityId, Integer pageParam, Integer pageSize)
29.0
31.0
Yes
public static ConnectApi.ChatterGroupPage getGroups(String communityId, Integer pageParam, Integer pageSize, ConnectApi.GroupArchiveStatus archiveStatus)
28.0
Yes
public static ConnectApi.GroupMember getMember(String communityId, String membershipId)
Type: ConnectApi.GroupMember
28.0
36.0
Yes
public static ConnectApi.GroupMemberPage getMembers(String communityId, String groupId, Integer pageParam, Integer pageSize)
31.0
Yes
public static ConnectApi.BatchResult[] getMembershipBatch(String communityId, List<String> membershipIds)
Type: BatchResult[]
The BatchResult getResults() method returns a ConnectApi.GroupMember object.
// 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()); } }
28.0
Yes
public static ConnectApi.GroupChatterSettings getMyChatterSettings(String communityId, String groupId)
28.0
Yes
public static ConnectApi.Photo getPhoto(String communityId, String groupId)
Type: ConnectApi.Photo
34.0
Yes
public static ConnectApi.GroupRecord getRecord(String communityId, String groupRecordId)
Type: ConnectApi.GroupRecord
33.0
Yes
public static ConnectApi.GroupRecordPage getRecords(String communityId, String groupId, Integer pageParam, Integer pageSize)
39.0
Yes
public static ConnectApi.Invitations inviteUsers(String groupId, ConnectApi.InviteInput invite)
Type: ConnectApi.Invitations
31.0
Yes
public static ConnectApi.Announcement postAnnouncement(String communityId, String groupId, ConnectApi.AnnouncementInput announcement)
Type: ConnectApi.Announcement
Use an announcement to highlight information. Users can discuss, like, and post comments on announcements. Deleting the feed post deletes the announcement.
To post an announcement, get information about an announcement, update the expiration date of an announcement, or delete an announcement, use the methods of the ConnectApi.Announcements class.
34.0
Yes
public static Void removeRecord(String communityId, String groupRecordId)
Type: Void
28.0
Yes
public static ConnectApi.GroupMembershipRequest requestGroupMembership(String communityId, String groupId)
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);
28.0
31.0
Yes
public static ConnectApi.ChatterGroupPage searchGroups(String communityId, String q)
28.0
31.0
Yes
public static ConnectApi.ChatterGroupPage searchGroups(String communityId, String q, Integer pageParam, Integer pageSize)
29.0
31.0
Yes
public static ConnectApi.ChatterGroupPage searchGroups(String communityId, String q, ConnectApi.GroupArchiveStatus archiveStatus, Integer pageParam, Integer pageSize)
36.0
Yes
public static ConnectApi.BannerPhoto setBannerPhoto(String communityId, String groupId, String fileId, Integer versionNumber)
Type: ConnectApi.BannerPhoto
Photos are processed asynchronously and may not be visible right away.
36.0
Yes
public static ConnectApi.BannerPhoto setBannerPhoto(String communityId, String groupId, ConnectApi.BinaryInput fileUpload)
Type: ConnectApi.BannerPhoto
Photos are processed asynchronously and may not be visible right away.
36.0
Yes
public static ConnectApi.BannerPhoto setBannerPhotoWithAttributes(String communityId, String groupId, ConnectApi.BannerPhotoInput bannerPhoto)
Type: ConnectApi.BannerPhoto
Photos are processed asynchronously and may not be visible right away.
36.0
Yes
public static ConnectApi.BannerPhoto setBannerPhotoWithAttributes(String communityId, String groupId, ConnectApi.BannerPhotoInput bannerPhoto, ConnectApi.BinaryInput fileUpload)
Type: ConnectApi.BannerPhoto
Photos are processed asynchronously and may not be visible right away.
28.0
Yes
public static ConnectApi.Photo setPhoto(String communityId, String groupId, String fileId, Integer versionNumber)
Type: ConnectApi.Photo
This method is successful only 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.
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);
28.0
Yes
public static ConnectApi.Photo setPhoto(String communityId, String groupId, ConnectApi.BinaryInput fileUpload)
Type: ConnectApi.Photo
This method is successful only 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.
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);
29.0
Yes
public static ConnectApi.Photo setPhotoWithAttributes(String communityId, String groupId, ConnectApi.PhotoInput photo)
Type: ConnectApi.Photo
This method is successful only 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.
29.0
Yes
public static ConnectApi.Photo setPhotoWithAttributes(String communityId, String groupId, ConnectApi.PhotoInput photo, ConnectApi.BinaryInput fileUpload)
Type: ConnectApi.Photo
This method is successful only 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.
28.0
Yes
public static ConnectApi.ChatterGroup updateGroup(String communityId, String groupId, ConnectApi.ChatterGroupInput groupInput)
Type: ConnectApi.ChatterGroup
This method is successful only 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.
String groupId = '0F9D00000000qSz'; String communityId = null; ConnectApi.ChatterGroupInput groupInput = new ConnectApi.ChatterGroupInput(); groupInput.isArchived = true; ConnectApi.ChatterGroups.updateGroup(communityId, groupId, groupInput);
29.0
Yes
public static ConnectApi.ChatterGroup updateGroupMember(String communityId, String membershipId, ConnectApi.GroupMembershipType role)
Type: ConnectApi.ChatterGroup
28.0
Yes
public static ConnectApi.GroupChatterSettings updateMyChatterSettings(String communityId, String groupId, ConnectApi.GroupEmailFrequency emailFrequency)
The value UseDefault uses the value set in a call to updateChatterSettings(communityId, userId, defaultGroupEmailFrequency).
28.0
Yes
public static ConnectApi.GroupMembershipRequest updateRequestStatus(String communityId, String requestId, ConnectApi.GroupMembershipRequestStatus status)
The Pending value of the enum is not valid in this method.
This method is successful only when the context user is the group manager or owner, or has Modify All Data permission.
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);
35.0
Yes
public static ConnectApi.GroupMembershipRequest updateRequestStatus(String communityId, String requestId, ConnectApi.GroupMembershipRequestStatus status, String responseMessage)
The Pending value of the enum is not valid in this method.
The maximum length is 756 characters.
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.
29.0
public static Void setTestSearchGroups(String communityId, String q, ConnectApi.ChatterGroupPage result)
Type: Void
28.0
public static Void setTestSearchGroups(String communityId, String q, Integer pageParam, Integer pageSize, ConnectApi.ChatterGroupPage result)
Type: Void
29.0
public static Void setTestSearchGroups(String communityId, String q, ConnectApi.GroupArchiveStatus, archiveStatus, Integer pageParam, Integer pageSize, ConnectApi.ChatterGroupPage result)
Type: Void