0

Hi I am trying to override standard delete button for a object "Claim" for a particular user role to prevent from delete & for other user roles the record should get delete. when i try with below code it prevents from deleting but not redirecting to the desired page mentioned in "Windows.Open()" just showing a blank page.

 <apex:page standardController="Claim__c">
 <script type="text/javascript">
 var con = {!$User.UserRoleId};
 if(con=='00E90000000ibNs')
 {
   window.onload (alert('Claim Caanot Be deleted'));
   window.open('/a08/o','_self');
  }
</script>   
</apex:page>
0

This type of requirement would be best fit to use a trigger on the object with the "before delete" operation. One primary reason is that you can override action override pages very easily with ?nooverride=1 appended to the URL.

Here is an example of a before delete trigger that will not allow them to bypass easily:

trigger prevent on Claim__c (before delete) {
  // do logic here to check if user is allowed to delete
  // e.g. check user's role or look at a custom setting you have setup, etc    
  // here is an example of checking roles, although I much prefer custom settings
  // to hardcoding it as I have done here as they do not require code changes
  // to update in the future
  boolean userAllowed = [select count() from User where UserRole.DeveloperName in ('AllowedRole1','AllowedRole2','AllowedRole3') and Id = :UserInfo.getUserId()] > 0;
  for (Claim__c claim : Trigger.old)
    {
      if(!userAllowed) {
        // user is not allowed to delete, use addError method on the SObject to stop them
        claim.addError('You cannot delete this record!');
      }
    }
}
0

Try window.location.href = '/a08/o';

to see if a popup blocker is stopping access.

0

A client-side redirection isn't a reliable solution. It is better to add an custom controller as extension to your VF page and put the logic into the Apex Controller.

--------------------Apex Controller Claim_Controller.cls------------------------------ ...

public PageReference reDirect() {

PageReference pageRef;

if($User.UserRoleId == 00E90000000ibNs) {

  pageRef = new PageReference('/a08/o');
  pageRef.setRedirect(true);

}

return pageRef;

}

...

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.