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
awilawil 

describe all fields / find all fields where isUpdatable, isAccessible are true

I want to create an interface for merging two custom object records. In order to do this, I want two columns with the values from each field (one field per row, including any possible custom fields), wherein the user can select the surviving value from one or the other records.

 

The problem is that I want to only display fields that are accessible (field describe "isAccessible") and that are updatable (field describe "isUpdatable").

 

I could describe the object and then walk the fields doing a describe on each field, but I would quickly hit the limit on number of describe calls per Apex script (10).

 

Is there another way?

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

Don't think the describe limits apply to the field describes, this worked fine for me from a VF page.

 

public String getFieldList() { String x=''; Map<String, Schema.SObjectField> m = Schema.SObjectType.Account.fields.getMap(); for (Schema.SObjectField f : m.values()) { Schema.DescribeFieldResult d = f.getDescribe(); if (d.isUpdateable()) x += d.getName() + ' ' + d.getLabel() + '<br>'; } return x; }

 


Message Edited by SimonF on 02-19-2009 09:24 AM

All Answers

SuperfellSuperfell

Don't think the describe limits apply to the field describes, this worked fine for me from a VF page.

 

public String getFieldList() { String x=''; Map<String, Schema.SObjectField> m = Schema.SObjectType.Account.fields.getMap(); for (Schema.SObjectField f : m.values()) { Schema.DescribeFieldResult d = f.getDescribe(); if (d.isUpdateable()) x += d.getName() + ' ' + d.getLabel() + '<br>'; } return x; }

 


Message Edited by SimonF on 02-19-2009 09:24 AM
This was selected as the best answer
SuperfellSuperfell
sorry for the formatting. stupid forum.
Abhishek Kumar SharmaAbhishek Kumar Sharma
Hi All,
 
/* Fetching all the fields of Account object */

Map<String, Schema.SObjectField> fieldMap = Schema.getGlobalDescribe().get('Account').getDescribe().fields.getMap();

/* Accessing writable and accessible fields from map */
                    for (Schema.SObjectField objectField : fieldMap.values())
                    {
                        Schema.DescribeFieldResult objectFieldResult = objectField.getDescribe();

                        if (objectFieldResult.isUpdateable() && objectFieldResult.isAccessible()) {
     System.debug('Field API Name -->'+objectFieldResult .getName()+' \nLabel --->'+objectFieldResult.getLabel());

                        }
                    }