5

Can I check whether a field is available on any of the page layout of an object using code? I have to set a checkbox if the field is available.

5
  • 3
    Is the use-case that you need to know if the current user has permission to see the field? Or are you designing some sort of custom user interface that specifically needs to look at page layouts for fields (which ignores the current user permission)? Aug 29, 2016 at 16:01
  • 2
    Yeah...you can find out if it's accessible with describes, e.g. Boolean isAccessible = MyObject__c.MyField__c.getDescribe().isAccessible();.
    – Adrian Larson
    Aug 29, 2016 at 16:09
  • @MikeKatulka - Yes I don't want to check the users permission. I want to know whether this field is on any of the page layout to know if this is user entered field.
    – Sneha
    Aug 30, 2016 at 7:05
  • 1
    @AdrianLarson - Thanks for the reply.. but the use case is to check if the field is present on the page layout.
    – Sneha
    Aug 30, 2016 at 9:39
  • 1
    That doesn't tell us anything about why. See also: X-Y Problem. You're focused on the Y and w're trying to dig into the X a little bit because it's quite an unusual thing to want to do.
    – Adrian Larson
    Aug 30, 2016 at 9:41

1 Answer 1

4

Vote for this idea if you feel the requirement is necessary for you:

Make Page Layout data available to apex via SOQL or Schema class

Page layout data should be available via the Schema apex class that retrieves metadata information on a limited read-only scale within apex classes, or should be available via SOQL.

Certain types of metadata are available in read-only mode in SOQL queries for developer use, even including apex classes and visualforce pages themselves. One object type not currently available without the use of the webservice API is page layouts and their component data.

With the introduction of dynamic inputField bindings in spring11 it's a better time than ever to expose page layouts to developers without having to do incredibly ugly workarounds like calling the webservice API from within apex classes.

This opens up worlds of new possibilities, including visualforce pages smart enough to respect sfdc layouts on actions like creation and edit - where visualforce and it's potential for automation is sorely needed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .