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

var result = 
        "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?


2 Answers 2


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.


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

  • 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 .