ConnectApi.BatchResult

The result of an operation returned by a batch method.

Usage

Calls to batch methods return a list of BatchResult objects. Each element in the BatchResult list corresponds to the strings in the list parameter passed to the batch method. The first element in the BatchResult list matches the first string passed in the list parameter, the second element corresponds with the second string, and so on. If only one string is passed, the BatchResult list contains a single element.

Example

The following example shows how to obtain and iterate through the returned ConnectApi.BatchResult objects. The code adds two group IDs to a list. One of group IDs is incorrect, which causes a failure when the code calls the batch method. After it calls the batch method, it iterates through the results to determine whether the operation was successful or not for each group ID in the list. The code writes the ID of every group that was processed successfully to the debug log. The code writes an error message for every failed group.

This example generates one successful operation and one failure.

List<String> myList = new List<String>();
// Add one correct group ID.
myList.add('0F9D00000000oOT'); 
// Add one incorrect group ID.
myList.add('0F9D00000000izf');

ConnectApi.BatchResult[] batchResults = ConnectApi.ChatterGroups.getGroupBatch(null, myList);

// Iterate through each returned result.
for (ConnectApi.BatchResult batchResult : batchResults) {
    if (batchResult.isSuccess()) {
        // Operation was successful. 
        // Print the group ID.
        ConnectApi.ChatterGroupSummary groupSummary;
        if(batchResult.getResult() instanceof ConnectApi.ChatterGroupSummary) {
           groupSummary = (ConnectApi.ChatterGroupSummary) batchResult.getResult();
        }
        System.debug('SUCCESS');
        System.debug(groupSummary.id);
    }
    else {
        // Operation failed. Print errors.
        System.debug('FAILURE');
        System.debug(batchResult.getErrorMessage());
    }
}