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
vp2595vp2595 

Error Message not working in Knowledge trigger

I am creating a Trigger on the Knowledge Object. It checks if today's date is less than a custom date. If true, then it should not allow article deletion.
 
trigger KAVTrigger on Knowledge__kav (before delete) {
    
    
    if(Trigger.isDelete){
        for (Knowledge__kav kav : Trigger.old) {
        
            if(date.today() < kav.customDate__c){
                kav.addError('You cannot delete this article');
            }
            
    	} 

    }
    
}

 
Kiran ChodavadiyaKiran Chodavadiya
Try this way. I hope it works.

Trigger KavTrigger on Knowledge__c (Before delete) {
    
    Date Today = system.Today();
    
    for (Knowledge__c kav : Trigger.old) {
           if (Today < kav.CustomDate__c) {
        kav.addError ('You cannot delete this article');
    }
    }
}
vp2595vp2595
Hi Kiran, I did try that, but the same problem, the article still gets deleted, without the error pop-up.