You need to sign in to do that
Don't have an account?
Uma 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
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
trigger ContentDocumentTrigger on ContentDocument (after insert) { static boolean firstRun = true; if(Trigger.isInsert && Trigger.isAfter){ for(ContentDocument cd: trigger.new){ if(firstRun){ if(cd.ownerid!=null){ List<user> userlist = [SELECT id,Profile.UserLicense.Name from user WHERE id=:cd.ownerid AND Profile.UserLicense.Name='Partner Community']; if(!userlist.isempty()){ 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){ toAddresses.add(custemailvales.Email_Addresses__c); } Messaging.Singleemailmessage email = new Messaging.Singleemailmessage(); email.setReplyTo('manjuzmail053@gmail.com'); email.setSenderDisplayName('Partner Upload File '); //String[] toAddresses = new String[] {'manjuzmail053@gmail.com'}; if(!toAddresses.isempty()){ email.setToAddresses(toAddresses); 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: https://moengage--partnersf.lightning.force.com/lightning/r/ContentDocument/'+cd.id+'/view </body></html>'; email.setSubject('A new file is uploaded by your Partner with file name : '+cd.Title); email.setHtmlBody(body); Messaging.sendEmail(new Messaging.SingleEmailmessage[] {email}); firstRun = false; } } } } } } }
@isTest 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]; } } }
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
002ItksIAC; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ZM_User_Sales_Org
_Hierarchy_Trigger: execution of BeforeDelete
i tried, its not working