What I'm trying to do is that when a checkbox is true, my rich-text area is required to have image but when I run this code, it still can proceed even no image in that rich-text area.
Kindly help me to fix this :(
my checkbox: TSM_Email__c
my rich text area: Attachment__c
So here is my current code and it pop out this error message.. is there any problem with my code?
trigger PraTrigger on I4_0_Project_Request_And_Approval__c (before insert, before update) {
for (I4_0_Project_Request_And_Approval__c p:Trigger.new){
String picString = p.Attachment__c.substringBetween('<img', 'img>');
if((p.TSM_Email__c == true) && (picString == null)){
p.addError('Picture is required to proceed');
}
}
}
I4_0_Project_Request_And_Approval__c
record would throw an error when updated. Have you tried adding any sort of debugging to see if the trigger code is being fired at all?addError
in both if and else, so practically any updation on the record should fail.