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
Harikrishna MandadapuHarikrishna Mandadapu 

not able to show only validation message through trigger, here is my code


trigger NoDeleteonIsAssignedTask on Task (before delete) 
 {
    String ProfileId = UserInfo.getProfileId(); 
    set<Id> setwhatId=new set<Id>(); 
    list<Task> lsttask=trigger.old;
    for(Task ta:trigger.old){
    setwhatId.add(ta.whatID);
    }
    list<employees__c> lst=[Select id from employees__c where id in :setwhatId];
    
        for (Task a : Trigger.old) { 
            if( lst.size()>0 )    
                 a.addError('You can\'t delete this record!'+a.id);
            }
            }
Harikrishna MandadapuHarikrishna Mandadapu
Validation Errors While Saving Record(s)
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Deletion of task is not allowed". 

Click here to return to the previous page.
this is the validation message I am getting
Head In CloudHead In Cloud
Hi Harikrishan,

You can check any validation rules on task object with message "Deletion of task is not allowed".

If you can not find any validation rule with this message, then this  message is coming from a trigger from a package installed in your org.

Please mark as best answer if it solves your issue. Thanks
VineetKumarVineetKumar
Check if you have delete permission on the object