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
sandeep3385sandeep3385 

How to make a field display only from an apex class?

While opening a visual force page i would like to see some fields displayonly dynamically. How to achieve this functionality through an apex class? is there any particular syntax like 'field.display = false' ? Please suggest.
BritishBoyinDCBritishBoyinDC
You can determine on a VF page if a field is shown using the "rendered" tag on an output field - look in the VF docs for an example
sandeep3385sandeep3385
I dont want it to be done on a VF page. It is a dynamic display of fields. So i have to do it from the class itself that drives the page.
BritishBoyinDCBritishBoyinDC

I don't understand the requirement then - what's the logic that determines if a field appears? 

 

 

sandeep3385sandeep3385

The display of some fields on the page are dependent on the roles(not profiles). So depending on the role of the user who logged in, fields should be displayed for him. So i have to do it from the class itself. To summarise, the code would look like this:

 

If role = x, field.display = true;

 

In this way, is there anything to control the field visibility?

BritishBoyinDCBritishBoyinDC
Yes - by using the render tag on the VisualForce page, because the Render tag is looking for a boolean tag that can be determined by a function in the Apex Class that returns a boolean (e.g. Does displayrole = users current role?)