0

I had to throw error messages based on permission sets in a custom button. So i did it like below,

var result = 
    sforce.connection.query(
        "SELECT Id " +
        "FROM PermissionSetAssignment " +
        "WHERE PermissionSetId = '0paahhysgshj768' " +
        "AND AssigneeId = '{!$User.Id}'"
    );

   var psAssignment = result.getArray("records");
   if(psAssignment.length === 0){ 
      alert('You dont have access to this functionality.'); 
   }

This works fine. But how can I avoid hardcoding the Permissionset Id in the query. I know we can store it in custom labels and use it. But, is there any way I can do this by permission set name?

0

2 Answers 2

4

In SoQL,

[SELECT PermissionSetId, PermissionSet.Name
FROM    PermissionSetAssignment
WHERE   AssigneeId = :UserInfo.getUserId()
AND     PermissionSet.Name = 'A Name'];

is perfectly acceptable. It should also be ok in a custom button.

0
0

One solution is put the Id in Custom Label and then access the custom label in custom button. Thanks .

Use a Custom Label in a Custom Link/Button

1
  • Ya I know i have that option open, but I want a way to query based on permissionsetname
    – Anurag
    Commented Jun 2, 2016 at 21:04

You must log in to answer this question.

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