0

I'm in the process of finalizing a process which is meant to prevent non-sysAdmin users from deleting Contact records in Salesforce. I have an addError on the trigger already to prevent users from doing it that way unless in a merge situation, but because of our sharing rules when they click the button it's not surfacing my custom error message in some situations so I'm trying to implement a custom override of the button as a catch-all. The alert to non-admins works fine, but when trying to execute an allowed delete as an admin the page gets caught it some sort of processing loop and never does anything. Here's the page:

<apex:page standardController = "Contact"
       action="{!IF($Profile.Name != 'System Administrator', null, URLFOR($Action.Contact.Delete, Contact.Id, [nooverride=1]))}">
<script>
  window.onload=function(){
    alert('You may not delete records.  Please use the deactivation button on the record instead.');
    window.history.back();
    };

I'm a bit stuck at the moment getting the admins to complete the action properly, so would appreciate any insight how to accomplish it. Thanks.

0

Figured it out, I was missing one of the parameters for the URLFor portion:

<apex:page standardController="Contact"
       action="{!IF($Profile.Name != 'System Administrator', null, URLFOR($Action.Contact.Delete, Contact.Id, [nooverride=1], true))}">
<script>
  window.onload=function(){
    alert('You may not delete records.  Please use the deactivation button on the record instead.');
    window.history.back();
    };

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.