Delete Case button access removed while keeping Delete Case access on object for merge purpose

casedeletedevelopermergepermissions

I have a requirement to remove the access for specific users, on the Delete case List View button.
These users should still have Delete access on the Case object, in order to be able to merge cases.
Also, these users are part of a team in which senior users and the manager should be able to have access to Delete Case button.

Does anyone have any idea about how can I do this?
I've tried different approaches but neither of them worked as expected. One of them was to create custom permission and to check it the before delete trigger and add an error message with addError method, but that was also limiting the merge access.

Thanks in advance!

Best Answer

As far as a trigger goes, you can check in an after delete trigger if MasterRecordId is set, and if so, you know you have a merge on your hands:

trigger BlockDeleteButNotMerge on Case (after delete) {
  for(Case record: Trigger.old) {
    if(record.MasterRecordId == null) { // And any other conditions
      record.addError('You cannot delete this case.');
    }
  }
}

Note that merging requires Delete and Edit Case permissions, so you can't outright block deletes just from Profile Permissions. A trigger is likely the correct solution in this situation.

Related Topic