You need to sign in to do that
Don't have an account?
LIM 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
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'); } } }
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()