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
OpsterOpster 

Query a Custom Setting to find Current User's permissions

I have created a custom setting from which I am able to restrict access to editing a text box on certain Visual Force pagesThis works greatHowever I am running into an issue when I want to query against the custom setting to find out the user's permissions via the API


From my APEX code I am able to do the following to get the Instance value of the custom setting based on the current user's PID

 

SomeCustomSetting__c.getInstance(pid);

 

How can I accomplish the same thing using a SOQL query?

Best Answer chosen by Admin (Salesforce Developers) 
aalbertaalbert

Add a WHERE clause to filter by the user's profile id. 

 

Select <fields> from CustomSetting__c where SetupOwnerId = <insert profile Id>

 

 

All Answers

aalbertaalbert

You can query custom settings using SOQL in the API.

 

For example,

       Select a.SetupOwnerId, a.Name, a.Id From ListSetting__c a

 

OpsterOpster

Two rows returned from your example.

 

That query is helpful because it returns the PID for one of the result rows, and the other is the org default.

 

But how can I get back just one row giving me the permissions based on the current users profile?

 

So the query will be run as the current user and I just want to know do I make this text field editable = TRUE, or FALSE?

 

I dont want to have to compare the PID's to the Current Users PID if possible.

 

thanks

aalbertaalbert

Add a WHERE clause to filter by the user's profile id. 

 

Select <fields> from CustomSetting__c where SetupOwnerId = <insert profile Id>

 

 

This was selected as the best answer