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?


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
    Jun 2 '16 at 21:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.