function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Uma PrabhakarUma Prabhakar 

How to resolve this error in the test class

Hello Salesforce Expertrs 

i am new to the salesforce and i am trying to write test class for the Content document trigger, So when partner user tries a Upload a document through files, automatically he gets email saying that document has been uploaded with the document link, the trigger was successful and with great difficulty i wrote a test class with 100% code coverage, but when i see the test result i see that there is erro "INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY" i have checked in the profile, as well as the OWD settings, still i was not able to resolve this issue, any help will be highly appreciated

User-added image
trigger ContentDocumentTrigger on ContentDocument (after insert) {
    static boolean firstRun = true; 
    if(Trigger.isInsert && Trigger.isAfter){
        for(ContentDocument cd:{ 
                    List<user> userlist = [SELECT id,Profile.UserLicense.Name from user WHERE id=:cd.ownerid AND Profile.UserLicense.Name='Partner Community'];
                        List<Partner_Upload_Email_Addresses__mdt> custmeta = [select id,Email_Addresses__c from Partner_Upload_Email_Addresses__mdt];
                        String[] toAddresses = new String[]{};
                            for(Partner_Upload_Email_Addresses__mdt custemailvales: custmeta){
                        Messaging.Singleemailmessage email = new Messaging.Singleemailmessage();
                        email.setSenderDisplayName('Partner Upload File ');
                        //String[] toAddresses = new String[] {''};
                            String body = '<html><body>Please note: A new document has been added\n \n ';
                            body += 'File name: '+ cd.title+'\n\n' ;
                            body += 'Created By: '+ cd.createdbyid+ '\n\n';
                            body += 'Created Date: '+ cd.CreatedDate+ '\n\n';
                            body += 'link to file:''/view </body></html>';
                            email.setSubject('A new file is uploaded by your Partner with file name :  '+cd.Title);
                            Messaging.sendEmail(new Messaging.SingleEmailmessage[] {email});
                            firstRun = false;

public class ContentDocumentTestclass {
    public static testmethod void ContentDocumentInsertTest()
        List<user> userlist = [SELECT id,Profile.UserLicense.Name,isactive from user WHERE Profile.UserLicense.Name='Partner Community' AND isactive=true];
        System.runAs(userlist[1]) {
            // The following code runs as user 'u' 
            System.debug('Current User: ' + UserInfo.getUserName());
            System.debug('Current Profile: ' + UserInfo.getProfileId());

            ContentVersion contentVersionInsert = new ContentVersion(
                Title = 'Tes11t',
                PathOnClient = 'Test1.jpg',
                VersionData = Blob.valueOf('Test 11Content Data'),
                IsMajorVersion = true
            insert contentVersionInsert;
            system.debug('User' + UserInfo.getUserName());
            List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];

Leanbridge TechnologiesLeanbridge Technologies
e have an immediate need to resolve the errors in the test class for a trigger.
The trigger, test class, and any supporting metadata is included. Edit the test class only to ensure the tests complete successfully, and ensure coverage is above 90%.
Below are the error messages we are seeing:
Test failure, method: Test_ZM_User_Sales_Org_Hierarchy_Handler.testUSOHierarchy 
-- System.DmlException: Delete failed. First exception on row 0 with id a12F0000 
_Hierarchy_Trigger: execution of BeforeDelete 

You can use real data in test class if really necessary by using @isTest(SeeAllData=true)
Uma PrabhakarUma Prabhakar

i tried,  its not working