You need to sign in to do that
Don't have an account?
Mila Johnson
Need to limit all users (including admins) from deleting accounts except for one or two users?
We have a before delete trigger on the account to prevent account deletion for all. So how can we make an exception for just one or two users?
trigger preventAccountDeletion on Account (before delete) {
for(Account acc : trigger.old){
acc.adderror('Account Cannot be deleted');
}
}
trigger preventAccountDeletion on Account (before delete) {
for(Account acc : trigger.old){
acc.adderror('Account Cannot be deleted');
}
}
You can get the user information i'e user id from UserInfo.getUserId() and if that does not match with that id you can add the above acc.adderror method as below.
Let me know if you face any issue.
If this solution helps, Please mark it as best answer.
Thanks,
Can we use username instead?
And if we need to add more users to this trigger in the future how can we do that?
You need to add user Id in custom metadata and can compare in trigger. in future i fyou want to increase number of user then you don't need to touch trigger just add new user ids in metadata
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Thanks for your reply!
I'm new to triggers, can you please guide me on how to do that.
OR (If you could help me with this)
the other solution I want to implement is having a checkbox on the User object and when true it will let them bypass the trigger.
Mila.