• Purvi Gupchup 2
  • 0 Points
  • Member since 2019

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 1
i have created a trigger on task so that task records cannot be deleted for a particular profile/record type:

trigger taskDelete on Task (before delete)
      system.debug('inside taskdelete');
      Id taskId;
      ID shipperRecordType = [SELECT Id FROM RecordType WHERE Name = 'Interaction'].Id;
       for(task a:Trigger.old)
          if(shipperRecordType == a.recordTypeId)
            system.debug('a.recordTypeId' + a.recordTypeId);
            system.debug('shipperRecordType'+ shipperRecordType);
            a.addErro.('you cannot delete this task');

the trigger is working properly but the error message is coming like this on the next page:

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 "you cannot delete this task".
Is there any workaround for this???