how to fix : System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, 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.: [NetworkId]

 


@isTest

public with sharing class BatchNextworkissueTest{

   @isTest static void check(){

Account acc;

  Id accCustRecTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Customer').getRecordTypeId();

Id profileId = [SELECT Id from Profile where profile.name = 'Customer Community User'].Id;

   acc = TestDataFactory.createAccount('TestAccount',accCustRecTypeId);

Database.insert(acc); 

//Create contact

Contact contact1 = new Contact(

FirstName = 'Test katta',

Lastname = 'katta',

AccountId = acc.Id,

Email =  'katta@test.com'

);

Database.insert(contact1);

User u = TestDataFactory.createUser('',profileId,'katta','kattaCommUser');

u.ContactId=contact1.id;

insert u;

here we need to retrive networkId id and 

Id networkrecId = [SELECT Id FROM Network LIMIT 1].Id;

System.runAs(u) { 

ContentVersion content=new ContentVersion(); 

content.Title='Katta_Picture1'; 

content.PathOnClient='/' + Katta.Title + '.jpg'; 

Blob bodyBlob=Blob.valueOf('Sfdc katta Body'); 

content.VersionData=bodyBlob; 

content.LinkedEntityId=acc.id;

content.origin = 'H';

// we need to add network id on ContentVersion object 

content.NetworkId = networkrecId ;

insert content;

ContentDocumentLink contentlink=new ContentDocumentLink();

contentlink.LinkedEntityId=q.id;

contentlink.contentdocumentid=[select contentdocumentid from contentversion where id =: content.id].contentdocumentid;

contentlink.ShareType = 'I';

contentlink.Visibility = 'AllUsers';  

   insert contentlink;

}  

Test.startTest();

BatchNextworkissuefiles x = new BatchNextworkissuefiles();

database.executeBatch(x); 

Test.stopTest();        

}

}

Resolution : I have resolved the network issue error by inserting network id on ContentVersion object 

Post a Comment

0 Comments