You need to sign in to do that
Don't have an account?
James McVicar 6
Trying to stop deletion of records on a custom object
We have a custom object called FMS Work Orders. Our users must have the "modfy all" permission, but I do NOT want them to delete Work Order records. I have followed this example to set up a trigger which stops the deletion of a record. The problem is the test class runs, cannot delete the record, which is the desired behaviour, but treats the test as a fail. Can anyone help pont out what's wrong with the test class?
Trigger:
Test Class
Trigger:
trigger PreventWODeletion on FMS_Work_order__c (before delete) { for(FMS_Work_order__c FWO : TRIGGER.OLD){FWO.ADDERROR('Work Order cannot be deleted');} }
Test Class
@isTest private class testPreventWODeletion { static testmethod void PreventWODeletion1() { FMS_Work_order__c FWORecord = new FMS_Work_order__c(); FWORecord.Issue_Description__c='Test123'; FWORecord.Case_number__c='5006E000004jB49QAE'; insert FWORecord; try{ delete FWORecord; } catch(DMLException e){ system.assert(e.getMessage().contains('Work Order Cannot be deleted'),'Work Order Cannot be deleted'); } } }
All Answers
Can you please provide error you are getting
Modify the try block of your code as this:
Let me know if it helps.
Thanks!
Thank you, worked first time!