You need to sign in to do that
Don't have an account?
KRISHNAMURTHY KOLUMAM ANANTHARAMAK
How do I write a test class for the below code ?
I am trying to send an email with attachment whenever a pdf is uploaded in Notes and attachment object. How do I write a test class ? Kindly help.
trigger EmailTrigger on ContentVersion (after insert){ if(Trigger.isAfter){ List<Messaging.SingleEmailMessage> allMessages = new List<Messaging.SingleEmailMessage>(); if(Trigger.isInsert){ for(ContentVersion cv : trigger.new){ Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment(); attachment.setBody(Blob.valueof(cv.ContentBodyId)); attachment.setFileName(cv.Title + '.' + cv.FileType); Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage(); message.toAddresses = new String[] { 'andre.nobre@cleantechsolar.com' }; message.ccAddresses = new String[] {'krishnamurthy.ka@cleantechsolar.com'}; message.subject = 'Test Mail'; message.plainTextBody = 'Attached file name: ' + cv.Title; message.setFileAttachments(new Messaging.EmailFileAttachment[] {attachment}); allMessages.add(message); } } Messaging.sendEmail(allMessages); } }
Let us know if this will help you
There is an issue in 8 th line. Please check the quotation and can you send me ?
It says unsupported identifier.
see the below pic:
I am getting the below error :
There is something wrong. Could you please correct and revert and also it covers 0% of the code ?
Trigger should be like below
Test Class should be like below
I tested the same in my developer org and got 94% (16/17) code coverage.
Let me know if this will help you