You need to sign in to do that
Don't have an account?
Swetha B 7
Code Coverage Helper
Trigger
trigger Attchementsharing on ContentDocumentLink (before insert) { Set<Id> Ids = new Set<Id>(); for (ContentDocumentLink cdl : trigger.new) { String id = cdl.LinkedEntityId; if (id.substring(0,3) == '02s') { Ids.add(Id); } else if (id.substring(0,3) == '500'&& cdl.visibility !='AllUsers') { cdl.visibility ='AllUsers'; } } Map<ID, EmailMessage> m = new Map<ID, EmailMessage>([SELECT Id, RelatedToId FROM EmailMessage where Id IN:Ids]); List<ContentDocumentLink> docs = new List<ContentDocumentLink>(); for (ContentDocumentLink cdl : trigger.new) { String id = cdl.LinkedEntityId; if (id.substring(0,3) == '02s') { ContentDocumentLink sr = new ContentDocumentLink(); sr.sharetype = 'I'; sr.visibility = 'AllUsers'; sr.ContentDocumentId = cdl.ContentDocumentId; sr.LinkedEntityId = m.get(Id).RelatedToId ; docs.add(sr); } } If (docs.size()>0){ Insert docs; } }Test Class: Current Code Coverage is 55%, Please help me to get 100%
@IsTest public class Attachementsharing_Test { static testmethod void testmethod1(){ Test.startTest(); Case cs = new Case(SuppliedName='test Case',SuppliedEmail='Test@test.com', Category__c='Client'); insert cs; ContentVersion content=new ContentVersion(); content.Title='Header_Picture1'; content.PathOnClient='/' + content.Title + '.jpg'; Blob bodyBlob=Blob.valueOf('Unit Test ContentVersion Body'); content.VersionData=bodyBlob; //content.LinkedEntityId=sub.id; content.origin = 'H'; insert content; ContentDocumentLink sr=new ContentDocumentLink(); sr.LinkedEntityId=cs.id; sr.contentdocumentid=[select contentdocumentid from contentversion where id =: content.id].contentdocumentid; sr.ShareType = 'I'; sr.Visibility = 'AllUsers'; insert sr; Test.stopTest(); } }
All Answers
Appreciate your response!
Yes, 02S id for an Email Message object. Please let me know how to pass the substring in the test class.
Kindly help with my trigger code coverage.
Thank you,
Swetha