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
LakshmanLakshman 

How to validate if User has particular profile permission set in an Apex class?

Hi All,

 

I want to know how can I query for Users having a particular profile permission sets in an Apex class. I am doing following query:

 

SELECT PermissionSetId FROM PermissionSetAssignment WHERE AssigneeId= :UserInfo.getUserId() AND PermissionSet.Name = 'EntityFasadUser'

 

There is an compilation error as below:

Save error: sObject type 'PermissionSetAssignment' is not supported.

 

Please help me on this. Thanks in advance.

 

Regards,

Lakshman

Best Answer chosen by Admin (Salesforce Developers) 
raseshtcsraseshtcs

Try changing the version of the classs to API version 22.0 and later.

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_permissionset.htm

All Answers

raseshtcsraseshtcs

Try changing the version of the classs to API version 22.0 and later.

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_permissionset.htm

This was selected as the best answer
LakshmanLakshman

Cheers it works!!!

Thanks a lot.

 

Regard,

Lakshman

LakshmanLakshman

Hey buddy,

 

Inspite of changing the API version I still get this error for a profile, any thoughts on this?

raseshtcsraseshtcs
What is the error...
LakshmanLakshman

Same error I am getting for a profile don't know what I need to enable in the permission set. Any help is appreciated.

 

Regarda,

Lakshman

raseshtcsraseshtcs
Add the class to the list of the profile you are testing with.....
LakshmanLakshman

Class and Page both are added. I think I am missing some System permission.

LakshmanLakshman

This is strange the PermissionSet object is not yet supported in VisulaForce Ajax API. When I query the same in the Apex class it works fine and when I try to query in the Page it doesnt.

But when I Enable Modify All permissions it works in page as well.

Still not able to get the exact cause. Did you get anything on this?

 

Regards,

Lakshman

Rahul_sgRahul_sg

try removing PermissionSetAssignment query out of your controller in a public class method and access that method from your controller.