You need to sign in to do that
Don't have an account?
how to write a test class for this? I'm very new to this
public class wv6_ContactTriggerHandler {
public static FINAL String STR_PreventDeleteWithoutMerge_ERROR = Label.PreventDeleteWithoutMerge;
public static FINAL Boolean hasPermission = FeatureManagement.checkPermission('Allow_Contact_Deletes');
public static void checkDeletePermissions(List<Contact> contactList, Map<Id,Contact> oldContactMap){
if(hasPermission) // user is authorized to delete without using Merge
return;
for(Contact c : oldContactMap.values()){
if(!Test.isRunningTest() && c.MasterRecordId == null){
c.addError(STR_PreventDeleteWithoutMerge_ERROR);
}
}
}
}
public static FINAL String STR_PreventDeleteWithoutMerge_ERROR = Label.PreventDeleteWithoutMerge;
public static FINAL Boolean hasPermission = FeatureManagement.checkPermission('Allow_Contact_Deletes');
public static void checkDeletePermissions(List<Contact> contactList, Map<Id,Contact> oldContactMap){
if(hasPermission) // user is authorized to delete without using Merge
return;
for(Contact c : oldContactMap.values()){
if(!Test.isRunningTest() && c.MasterRecordId == null){
c.addError(STR_PreventDeleteWithoutMerge_ERROR);
}
}
}
}
Assuming this is part of a Contact trigger on Delete you could do something like this
All Answers
Assuming this is part of a Contact trigger on Delete you could do something like this
I appreciate the template! Part of my issue was that I needed to update the contact records to be owned by the user running as, so they could delete (or not) and get the error I expected. Once I did that, it worked! :) #learningdaily