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
LIM AI KHOONLIM AI KHOON 

Coverage Code Checking if the field have image

Hi anyone can help on how to do code coverage for this trigger ? 
This trigger to prevent user submit without image attachment field [rich text field]

Thank you
trigger PraTrigger on RequestApproval__c (before insert, before update) {
    for (RequestApproval__c p:Trigger.new){
    if(p.TSM_Email_c && (String.isBlank(p.Attachmentc) || (String.isNotBlank(p.Attachmentc) && !p.Attachment_c.contains('<img')))){
        p.addError('Picture is required to proceed');
    }
            
}
}

 
Akshay SAkshay S
Hi Lim,

Insert record in a try block and in catch block assert error message.
in test class :

RequestApproval__c reqAppObj = new RequestApproval__c();
<map fields>
[dont insert data in richTextField]
.
.
test.startTest()
Try{
            insert reqAppObj;
        }
        Catch(Exception e){
            System.assert(e.getMessage().contains('Picture is required to proceed')); 
        }
test.stopTest()