You need to sign in to do that
Don't have an account?
Staci
test class coverage for attachments in email-to-case
I have the following code to move attachments from the inbound email message into Attachments - we are still in classic
I have 53% coverage right now. Can't figure out how to get the last half of this code covered.
I have 53% coverage right now. Can't figure out how to get the last half of this code covered.
//test coverage in DSSEmailHandlerTest trigger CW_emailAttachmentReassigner on Attachment (before insert) { map<id, id> msgIdToParentId = new map<id, id>(); Attachment[] reparents = new Attachment[]{}; Schema.sObjectType email = emailmessage.getsobjecttype(); for(Attachment a : trigger.new) { if(a.parentid != null){ //see if the parent is an EmailMessage if(a.parentid.getsobjecttype() == EmailMessage.getsObjectType()) { //Test code from here down msgIdToParentId.put(a.parentid, null); reparents.add(a); } } } if(!reparents.isEmpty()){ for(EmailMessage em : [select id, parentID from EmailMessage where id =: msgIdToParentId.keyset()]){ msgIdToParentId.put(em.id, em.parentId); } for(Attachment a : reparents) { a.parentId = msgIdToParentId.get(a.parentId); } } }
@isTest private class DSSEmailHandlerTest { public static Blob createAttachmentBody(){ String body = 'XXXXXXXXXXXXX'; return Blob.valueof(body); } public static testMethod void testmyHandlerTest() { Case c = new Case(); insert c; Messaging.InboundEmail email = new Messaging.InboundEmail(); Messaging.InboundEnvelope env = new Messaging.InboundEnvelope(); email.subject = 'ref'; email.PlainTextBody = 'test body'; // Add a Binary attachment to the email message! Messaging.InboundEmail.BinaryAttachment attachment = new Messaging.InboundEmail.BinaryAttachment(); attachment.body = blob.valueOf('my attachment content'); attachment.fileName = 'filename.txt'; attachment.mimeTypeSubType = 'text/plain'; email.binaryAttachments = new Messaging.inboundEmail.BinaryAttachment[] { attachment }; DSSEmailHandler m = new DSSEmailHandler(); m.handleInboundEmail(email, env); } }
try with below code. You will get 100% coverage.
If this helps, Please mark it as best answer.
Thanks!!
All Answers
try with below code. You will get 100% coverage.
If this helps, Please mark it as best answer.
Thanks!!