简体   繁体   中英

How to render VisualForce page inputCheckBox in custom controller according to user profile?

I have a VisualForce page that has a custom controller and I want users to see components like inputCheckBox only if they have the accessible option in their profile. I've read that when using a custom controller the VF is running in system context. I've tried using the ObjectType to render the checkbox if the user has access and it did rendered even-though the profile was blocked to this specific field. My code where Billable is the field I'm trying to hide:

apex:inputCheckBox style="width:15px;" rendered="{!$ObjectType.MyObject__c.accessible} value="{!SelectedMO.Billable}"/>

Do you really need a custom component (everything built from scratch)? If you'll use standard(set)controller and custom extension the whole visibility thing should be done for you automatically and the less code the better...

Alternatively you might querying the Profile/PermissionSet-related tables. I say query because describe calls in the controller will probably return same thing as this accessible you've used. Here's the diagram: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_erd_profile_permissions.htm

This should be a good start:

SELECT Field, PermissionsEdit,PermissionsRead
FROM FieldPermissions
WHERE Parent.Profile.Name = 'System Administrator'
    AND SobjectType = 'Account'
LIMIT 10

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM