function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anish Mahadik 1Anish Mahadik 1 

Custom Button visibility using permission set in VF page

Hi All,

I have custom button (Edit and clone ) in my VF page and my requirement is for one particular permission set i need to hide those button which i created using commandbutton expression. Please help me on these.

Thanks,
Anish
Best Answer chosen by Anish Mahadik 1
Anish Mahadik 1Anish Mahadik 1
Hi All,

I used following code and it works for me.

Public Set<String> permissionSetNameList;
    Public Set<String> userPermissionList;
    Public Set<String> userProfileSet;
    Public Boolean relatedListFlag {get;set;}
 public void Custombutton()
         {
                    permissionSetNameList =New set<String>();
                userPermissionList=New set<String>();
                userProfileSet=New set<String>();

                for(PermissionSetAssignment permission : [SELECT Id, PermissionSet.Name FROM PermissionSetAssignment WHERE AssigneeId =:UserInfo.getUserId() ])
            {
                 permissionSetNameList.add(permission.PermissionSet.Name); 
                                          
            }          
            userPermissionList.addAll(permissionSetNameList);   
            
            for(User userIterator : [SELECT Id, Profile.Name FROM User WHERE Id =: UserInfo.getUserId()])
            {
                userProfileSet.add(userIterator.Profile.Name);
            }                 
            if( userPermissionList.contains('Test_Permission')== true)
            {
                relatedListFlag = true;       
            } 
       }

public TestController(ApexPages.standardController controller)
{
Custombutton();

}

And also added !not(relatedListFlag) in render property of VF page.

Thanks,
Anish

All Answers

Raj VakatiRaj Vakati
You can use custom permissions rather than permission set.

 

https://help.salesforce.com/articleView?id=custom_perms_overview.htm&type=5
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_variables_global_permission.htm
http://www.salesforcehacker.com/2014/06/choose-your-own-adventure-with-custom.html
http://www.simplysfdc.com/2014/10/salesforce-custom-permission-for.html
Anish Mahadik 1Anish Mahadik 1
Hi Raj,

As i have created button in my VF page coding. So i am not able set the custom permission for that. Please let me know any other alternative.

Thanks,
Anish
Anish Mahadik 1Anish Mahadik 1
Hi All,

I used following code and it works for me.

Public Set<String> permissionSetNameList;
    Public Set<String> userPermissionList;
    Public Set<String> userProfileSet;
    Public Boolean relatedListFlag {get;set;}
 public void Custombutton()
         {
                    permissionSetNameList =New set<String>();
                userPermissionList=New set<String>();
                userProfileSet=New set<String>();

                for(PermissionSetAssignment permission : [SELECT Id, PermissionSet.Name FROM PermissionSetAssignment WHERE AssigneeId =:UserInfo.getUserId() ])
            {
                 permissionSetNameList.add(permission.PermissionSet.Name); 
                                          
            }          
            userPermissionList.addAll(permissionSetNameList);   
            
            for(User userIterator : [SELECT Id, Profile.Name FROM User WHERE Id =: UserInfo.getUserId()])
            {
                userProfileSet.add(userIterator.Profile.Name);
            }                 
            if( userPermissionList.contains('Test_Permission')== true)
            {
                relatedListFlag = true;       
            } 
       }

public TestController(ApexPages.standardController controller)
{
Custombutton();

}

And also added !not(relatedListFlag) in render property of VF page.

Thanks,
Anish
This was selected as the best answer