Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on testing whether or not certain fields are accessible with FLS. At the moment, using the following method, I can only test one field at a time.

I'm fairly new to APEX, and I'm wondering can I test multiple fields somehow? Possibly loop through a list of fields I could pass into the FieldInformation method?


public String FieldInformation() {

    if (!Schema.sObjectType.Opportunity.fields.Amount.isAccessible()){
      System.debug('IS NOT ACCESSIBLE');
      return '';

    Schema.DescribeFieldResult drField = Opportunity.Amount.getDescribe();
    System.debug('GET LABEL: ' +  drField.getLabel());
    System.debug('GET PICKLIST VALS: ' + drField.getPicklistValues());
    System.debug('GET IS ACCESSIBLE: ' + drField.isAccessible());
    System.debug('GET IS CREATABLE: ' + drField.isCreateable());
    System.debug('GET IS NILLABLE: ' + drField.isNillable());
    System.debug('GET IS UPDATEABLE: ' + drField.isUpdateable());       
    return '';


static void getOpp() {

    Opportunity opportunity = new Opportunity(name = 'Test opportunity', StageName='Prospecting',;

    insert opportunity;

    ApexPages.currentPage().getParameters().put('OppId', opportunity.Id);

    temp_FLS FLSController = new temp_FLS();

    FLSController = new temp_FLS(); 


share|improve this question
up vote 2 down vote accepted

The describe results for the SObjectType include a map of field names to SObjectField tokens. So for example this will output the field describe information for all fields:

Map<String, SObjectField> m = Opportunity.SObjectType.getDescribe().fields.getMap();
for (String name : m.keySet()) {
    DescribeFieldResult r = m.get(name).getDescribe();

and as you suggest you could iterate over a list of field names passed into your method instead of all the keys.

(There is no API to get multiple DescribeFieldResult objects returned in one call.)

share|improve this answer
Thanks for the informative answer Keith, really appreciate it! Sorry to ask a further question, but would passing a list of fields into this method be a complicated thing to do? As I mentioned above, I'm fairly new to Apex and Java. – Daft Jun 16 '14 at 11:23
No its easy as you can make your function public String FieldInformation(String[] names) and then loop over the names. – Keith C Jun 16 '14 at 12:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.