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
SydneyForceSydneyForce 

How to render an input field only if user has edit access to it

Hello,

 

I would like to know how to render an input field only if a user has edit access to a field.

 

This could be done by a Apex controller if necessary.

 

Right now I have an input field, but I don't want it rendered for users that have "read-only' access at field-level security for their profile.

 

Thank you,

Adrian

Best Answer chosen by Admin (Salesforce Developers) 
Imran MohammedImran Mohammed

In the controller you can declare a Boolean variable to decide whether the inputField should be rendered or not.

 

In controller class,

 

Public Bololean showField{get; set;}

//Somewhere initialise the field to false

 

Schema.DescribeFieldResult sdf = ObjectName.FieldName.getDescribe();

if(sdf.isCreateable() || sdf.isUpdateable())

{

 showField = true;

}

 

Then in VF page,

<apex:inputField value="{!mergefield}" rendered="{!showField}"/>

 

Hope that helps.

All Answers

Imran MohammedImran Mohammed

In the controller you can declare a Boolean variable to decide whether the inputField should be rendered or not.

 

In controller class,

 

Public Bololean showField{get; set;}

//Somewhere initialise the field to false

 

Schema.DescribeFieldResult sdf = ObjectName.FieldName.getDescribe();

if(sdf.isCreateable() || sdf.isUpdateable())

{

 showField = true;

}

 

Then in VF page,

<apex:inputField value="{!mergefield}" rendered="{!showField}"/>

 

Hope that helps.

This was selected as the best answer
SydneyForceSydneyForce

Thanks Imran.

 

That's exactly what I'm after.