+ Start a Discussion
sumit dsumit d 

FIELD_INTEGRITY_EXCEPTION, field integrity exception: unknown (invalid user or group: 0056u000001AjNo): [unknown]

Hi All,
         I have created a trigger to provide Apex sharing to the forum members but when i am inserting members i am getting following error:- Trigger_ForumMember: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: unknown (invalid user or group: 0056u000001AjNo): [unknown] Class.ForumMemberTriggerHelper.shareForumWithUser: line 42, column 1 Trigger.Trigger_ForumMember: line 15, column 1
My trigger and helper class given below:- 

trigger Trigger_ForumMember on Forum_Members__c (before insert, before update, before delete,
                                                    after insert, after update, after delete) {
    ForumMemberTriggerHelper.newForumMembers = Trigger.new;
    ForumMemberTriggerHelper.oldForumMembers = Trigger.old;
    ForumMemberTriggerHelper.newMapForumMembers = Trigger.newMap;
    ForumMemberTriggerHelper.oldMapForumMembers = Trigger.oldMap; 
        if(!ForumMemberTriggerHelper.runTrigger) {
    if( Trigger.isAfter) {
        if( Trigger.isInsert ){
Helper Class:- 
public class ForumMemberTriggerHelper {
    public static List<Forum_Members__c> newForumMembers = new List<Forum_Members__c>();
    public static List<Forum_Members__c> oldForumMembers = new List<Forum_Members__c>();
    public static Map<Id, Forum_Members__c> newMapForumMembers = new Map<Id, Forum_Members__c>();
    public static Map<Id, Forum_Members__c> oldMapForumMembers = new Map<Id, Forum_Members__c>();
     public static boolean runTrigger = TRUE;
     public static void shareForumWithUser(){
         Set<Id> contactIds = new Set<Id>();
        Map< Id, User> mapOfContactIdToUser = new Map<Id,User>();
        List< Forum__Share > lstForumShare = new List< Forum__Share >();
        for( Forum_Members__c fm : newForumMembers ){
            if( fm.Member__c != null ){
                contactIds.add( fm.Member__c );
        for( User ur : [ SELECT Id, ContactId 
                        FROM User 
                        WHERE ContactId IN : contactIds ] )
            mapOfContactIdToUser.put( ur.ContactId , ur );
        for( Forum_Members__c fm :  newForumMembers ){
            if( fm.Forum__c != null  ){
                if( mapOfContactIdToUser.containsKey( fm.Member__c )
                   && mapOfContactIdToUser.get( fm.Member__c ) != null ){
                       System.debug('Inside log');
                       Forum__Share sharing = new Forum__Share();
                       sharing.ParentId = fm.Forum__c;
                       sharing.AccessLevel = 'Edit';
                       sharing.RowCause = 'Manual';
                       sharing.UserOrGroupId = mapOfContactIdToUser.get( fm.Member__c ).Id;
                       lstForumShare.add( sharing );
        if( lstForumShare.size() > 0 ){
            insert lstForumShare;
Can anyone help me with this error?
SwethaSwetha (Salesforce Developers) 
HI Sumit,
I see you are performing  insert lstForumShare; in your code

As mentioned on

Customer Communities users do not have access to the full sharing model and therefore can't be added on a __Share record. The only way to share a record with a Customer Communities user is through Sharing Sets and Sharing Groups.

Also see https://salesforce.stackexchange.com/questions/198045/how-to-share-a-record-with-a-community-user


If this information helps, please mark the answer as best. Thank you