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
PlainviewPlainview 

Exposing a feature in an Apex Class to Users in Certain Profiles, Groups or Queues.



Hello,

We have an Apex Class (opportunityButtons), which is coded to expose a button on our opportunities to only a few specific User Id's. The Security link to the class is set to allow access to this class but not everyone under the listed profiles can see the button; only those whose record Id's appear in the code. I double-checked by adding my own User Id and it worked, so I know this is where this has been set-up.

My question is: what would be the logic to expose the button to everyone under a certain Profile as opposed to having to input each User's Id to allow access to the button.

The button appears on our "upgrade" opps layout for the User whose Id's appear in the code. Here are a couple of screenshots - one showing the button in question and the other, the related code.

Thanks for any help!

Best,
Julien

User-added imageUser-added image
Peter_sfdcPeter_sfdc
You can always just test for the current user's profile in Apex by using: 
UserInfo.getProfileId()
Chances are this won't be the same in Production and Sandboxes, but you can do a lookup of profiles and store in a map, then use this to check against profiles where you want to allow access.