You need to sign in to do that
Don't have an account?
prady-cm
Error [statusCode=INVALID_CROSS_REFERENCE_KEY ] while adding a user to a chatter group
I am trying to add user to a chatter group from apex. I am getting an error
"Error [statusCode=INVALID_CROSS_REFERENCE_KEY, code=[xmlrpc=1202, statusCode=INVALID_CROSS_REFERENCE_KEY, exceptionCode=INVALID_CROSS_REFERENCE_KEY, scope=PublicApi, http=400], message=This user can't be added to the group., fields=null]"
Here is the code i am using
lstCGM.add(new CollaborationGroupMember(CollaborationGroupId = lCGA[k].Chatter_Group_ID__c , // CollaborationRole = 'Member', MemberId = u[i].Id )); //Debugging for(CollaborationGroupMember cgmr : lstCGM) { system.debug('Processing the CGM record ' + cgmr); } if (lstCGM.size() > 0) { // Insert the CGM Records Database.SaveResult[] lsr = Database.insert(lstCGM, false); // Loop through the save results writing errors to the debug log for (Database.SaveResult sr : lsr) { if(!sr.IsSuccess()) { Database.Error err = sr.getErrors()[0]; System.debug(err.getMessage()); } } // END LOOP through the save results writing errors to the debug log }// END IF there are records to insert, insert them.
The debug logs return the correct ids
Processing the CGM record CollaborationGroupMember:{CollaborationGroupId=0F9E00000008cpwKAA, MemberId=005c0000000R2kQAAS} USER_DEBUG|[275]|DEBUG|This user can't be added to the group.
Checked the ids on the browser and they were valid.
Any idea what should be causing this?
What is the Profile of your User, for example, if it is 'Chatter External User', you will get exactly the same error.