0

I am trying to delete the related records on click of a button which is working fine.Now i want the delete logic to work only the profiles which contains 'xyz' in their name. I am getting an error 'TypeError: System Admin.contains not a function'.

Any other methods which i can use here.

 {!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
    {!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}
    alert('{!$Profile.Name}') 
    try{ 
        if('{!$Profile.Name}'.contains('xyz')){
2
  • 1
    Try replacing if('{!$Profile.Name}'.contains('pss')){ with if(String.valueOf({!$Profile.Name}).contains('pss')){ or if((String){!$Profile.Name}.contains('pss')){. Maybe the profile name needs to be typecasted as a String, although I'd expect it to be retrieved as a String so this is just a guess.
    – Dan Jones
    Commented Nov 21, 2016 at 14:06
  • I am currently trying includes() and i guess that will work. Will try your idea too Dan.Thanks a lot
    – Samir
    Commented Nov 21, 2016 at 14:08

1 Answer 1

2

Personally, I wouldn't do this, because it can cause you problems later. Instead, simply use Custom Permissions. Create a new custom permission, and you can check for it like this:

if({!$Permission.canDeletePss}) {
    // rest of code here

This allows you to specify the permission per profile or even as part of a permission set that can be assigned per user, at will, without having to modify your code.

2
  • Thanks for the idea.I didn't find any solid documentation to implement this as i am not aware of this.could you please guide me how i can implement this?Some good documents links would be awesome.
    – Samir
    Commented Nov 21, 2016 at 14:36
  • 1
    @Samir There's a link in the answer. To summarize, you (a) create a new custom permission in Setup, (b) edit any profiles and/or permission sets that should have this permission, and then (c) write the code as I've demonstrated above.
    – sfdcfox
    Commented Nov 21, 2016 at 15:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .