I'm trying to create a dependent picklist of objects and fields. I present a list of objects to the user, and depending on the object they select, I show the object's String fields in the second picklist.

I have an actionSupport with an onchange event for the object picklist. This rerenders the fields part and calls the getter.

I am an admin and have access to the object I select. To demonstrate this, in getFieldOptions() if I specifically set objectSelected = 'Contact', the initial page load correctly shows all Contact fields in the fields picklist. But if I select Contact from the objects drop-down, it fails with an "Insufficient Privileges" error. I don't know why it would work on page load and not on rerender. I have access to the VF page/Class in question.


              <div id="importManualObjects">
                    <apex:selectList size="1" value="{!objectSelected}">
                        <apex:selectOptions value="{!objectOptions}"/>
                        <apex:actionSupport event="onchange" reRender="fields"/>
                    <apex:outputPanel id="fields">
                        <apex:selectList size="1" value="{!fieldSelected}">
                            <apex:selectOptions value="{!fieldOptions}"/>

Apex snippet:

public String objectSelected {get;set;}
        public String fieldSelected {get;set;}
        public Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();

public List<SelectOption> getObjectOptions(){

             List<SelectOption> objects = new List<SelectOption>();
             objects.add(new SelectOption('--None--', '--None--'));

             for(Schema.Sobjecttype obj: gd.values()){

                Schema.DescribeSObjectResult s = obj.getDescribe();

                if(s.isAccessible() && s.isQueryable()){

                    SelectOption so = new SelectOption(s.getLabel(), s.getName());

             return objects;

        public List<SelectOption> getFieldOptions(){

            List<SelectOption> fields = new List<SelectOption>();
            fields.add(new SelectOption('--None--', '--None--'));

            System.debug('object selected is: '+objectSelected);
            System.debug('gd is: '+gd.get(objectSelected));

            if(objectSelected != null && gd != null && gd.get(objectSelected) != null){

                Schema.Describesobjectresult s = gd.get(objectSelected).getDescribe();

                if(s.isAccessible() && s.isQueryable()){

                    System.debug('is accessible and queryable');

                    Map<String, Schema.SObjectField> objectFields = s.fields.getMap();

                    for(Schema.Sobjectfield field: objectFields.values()){

                        Schema.Describefieldresult f = field.getDescribe();

                        //Only accept String types
                        if(f.isAccessible() && f.getType() == Schema.Displaytype.String){

                            SelectOption so = new SelectOption(f.getLabel(), f.getName());
                            System.debug('added '+so);

            return fields;                  

EDIT: Interestingly, the code works if I copy and paste to a new page. Right now it's part of a big page. I'm not sure why that would make a difference though.

EDIT2: Console error is

ERROR: POST https://.na12.visual.force.com/apex/ 500 (Server Error)

at A4J.AJAX.XMLHttpRequest.send A4J.AJAX.SubmitQuery A4J.AJAX.Submit onchange

  • is this on a force.com site?
    – Phil B
    Commented Aug 20, 2013 at 18:28
  • No, it's an ordinary VF in a dev org.
    – George S.
    Commented Aug 20, 2013 at 18:28

2 Answers 2


There was an <apex:inputFile>, which cannot be rerendered, in the same form. This caused the cryptic (and incorrect) insufficient privileges message.


When you debug the code, does it run all the way through? I looked through your code and at first glance everything appears to be in place correctly (outside of the assertEquals statement, you should remove that).

If your code does run all the way through, I have found that there are times when an error in the code can return an insufficient privileges error if for say, you redirect to an error page (this is typical when working on a Portal for instance) and your profile doesn't have access to that page. Just a guess right now.

  • Thanks Jesse. Basically, it doesn't even seem to enter the getFieldOptions method: I set debugging to FINEST and it just says CODE_UNIT_STARTED and CODE_UNIT_FINISHED. Since I am rerendering the same page (which has already loaded correctly) I am at a loss to explain the privileges problem. I thought it must be that I'm missing some permissions on the object to get the fields, but a) it works if I hardcode, and b) it fails for any object I select.
    – George S.
    Commented Aug 20, 2013 at 18:28

You must log in to answer this question.

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