+ Start a Discussion
Bhushan2710Bhushan2710 

How to insert a FeedComment of Type ContentComment in testclass?

Hello,

 

I am trying to insert a feedComment of contentcomment type on a feedpost in the follwing test method- 

when i run the test i get an error  saying "System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary.: []"

 

static testmethod void mytest(){
        Account Acc = new Account(Name = 'TestAccountBhushan',Phone = '040-754-7845');
        insert acc;  
        
        contentVersion cv = new contentVersion(
        pathonclient = 'My Document.docx',
        versionData = EncodingUtil.base64Decode('SampleImageFile')
        );
        insert cv;   
        //Inserting  post on chatter
        FeedItem textFeed = new FeedItem(
                Body = 'This is a text post',
                Type = 'TextPost',
                ParentId = acc.id               
        );          
        insert textFeed;
        
        FeedComment fc = new FeedComment(
            feedItemId = textFeed.Id,
            relatedRecordId = cv.id,
            commentBody = 'Test Comment Body'
            //commentType = 'ContentComment'
        );   
        insert fc;
        system.debug('****** Comment******'+ fc);

}

 

Thanks,

Bhushan

JimDeLongJimDeLong
Is this solved? I would try creating a user, then do a run as command. That might help.