Skip to main content
please help me...

i have an one profile xyz that have an multiple users.xyz profile has full access permission.

my question is to restrict only one user to delete permission on that profile.

can i use trigger?then reply me code pls....

thanks.
16 answers
  1. Mar 27, 2018, 12:57 PM
    Hi ,

    I test the same code and working fine. 

    Create a Custom Label Called  UserGroup and add userid (18 Digit) in comma separated value if you have multiple. 

     

    Handler Class

    public class CannotDeleteAccount {

    public static void NoDeleteAccount (List<Account> accounts){

    system.debug('before delete trigger');

    String Userid = UserInfo.getUserId();

    System.debug('Current User id'+Userid);

    set<string> strkey = new set<string>(Label.UserGroup.split(','));

    System.debug('strkey'+strkey);

    for (Account acc: accounts){

    If(strkey.contains(Userid)){

    acc.addError('You cannot delete the Account');

    }

    }

    }

    }

     

    Call the Method From trigger

    Trigger accountTrigger on Account (before delete) {

    if(Trigger.isBefore){

    System.debug('Inside the Trigger');

    CannotDeleteAccount.NoDeleteAccount(Trigger.Old);

    }

    }

    This should work without any issue. Simply Copy-Paste the above code will work. 
0/9000