You need to sign in to do that
Don't have an account?

Permission set coding for Custom button is not working.
Hi All,
I am trying to hide the custom button based on permission set.For that i already wrote a code but it is giving me an error.
public void Custombutton()
{
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;
}
I called the Custombutton() in controller .
Afte that i added the relatedListflag in rendered property of the button.
Vf Page Code
<apex:commandButton id="hideEditbtn1" Styleclass="btn btn-primary" action="{!makeFormEdit}" rendered="{!!isEditMode && relatedListFlag}" value="Edit" reRender="contentPanel,actProjHist,formId" oncomplete="loadToggle();hidePOC();showHeader();hideHelptext();"> </apex:commandButton>
But when i tested the app with Test_Permission . it is giving me an error
System.NullPointerException: Attempt to de-reference a null object
Please help me on this.
Thanks,
Anish
I am trying to hide the custom button based on permission set.For that i already wrote a code but it is giving me an error.
public void Custombutton()
{
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;
}
I called the Custombutton() in controller .
Afte that i added the relatedListflag in rendered property of the button.
Vf Page Code
<apex:commandButton id="hideEditbtn1" Styleclass="btn btn-primary" action="{!makeFormEdit}" rendered="{!!isEditMode && relatedListFlag}" value="Edit" reRender="contentPanel,actProjHist,formId" oncomplete="loadToggle();hidePOC();showHeader();hideHelptext();"> </apex:commandButton>
But when i tested the app with Test_Permission . it is giving me an error
System.NullPointerException: Attempt to de-reference a null object
Please help me on this.
Thanks,
Anish
The code is totally correct. Just i have intitalize the permissionSetNameList field and added !not(relatedListFlag) in rendered attribue of VF page. It resolve my issue.
Thanks,
Anish
All Answers
Public Set<String> permissionSetNameList;
Public Set<String> userPermissionList;
Public Set<String> userProfileSet;
Public Boolean relatedListFlag {get;set;}
public void Custombutton()
{
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();
}
This is the apex code used. Please let me know which values should i assign for permissionSetNameList to initialize.
Thanks,
Anish
The code is totally correct. Just i have intitalize the permissionSetNameList field and added !not(relatedListFlag) in rendered attribue of VF page. It resolve my issue.
Thanks,
Anish