+ Start a Discussion

IsClosed doesn't appear in Opportunity Describe calls

I'm trying to create an app that lets customers select an opportunity field from a picklist, and IsClosed is the primary field most will use.


However, my describe calls don't return it, likely because it is not truly an oppty field but rather an OpportunityStage field.


Is there any simple way to return IsClosed using an oppty describe call?


Code that populates the field list.  Note that ObjectName is dynamic - assume for this question it is equal to Opportunity.  Note I remove a bunch of field types, but IsClosed isn't a Reference type, and I'm pretty sure it isn't any of the others (anytype, base64, etc)


    public List<selectOption> getFieldNames(){
        List<selectOption> options=new List<selectOption>();
        List<String> fieldLabels=new List<String>();//included to create a sorted field name list
        Map<String,String> fieldLabelNameMap=new Map<String,String>();
        Boolean evaluateFields=False;
        if (evaluateFields){//if 1    
            SObjectType objToken = Schema.getGlobalDescribe().get(u.ObjectName__c); //assume this equals Opportunity
            DescribeSObjectResult objDef = objToken.getDescribe();
            Map<String, SObjectField> fieldMap = objDef.fields.getMap();//this doesn't return IsClosed as far as I can tell

            options.add(new selectOption('',''));
            for (String fName:fieldMap.keySet()){//for 1
                //Disallow unsupported field types

                //This disallows the unsupported types: text area, anytype, encrypted string, multiselect picklists, lookup fields, base64, reference fields, and URL's
                    //Disallow fields that aren't updatable
                        fieldLabelNameMap.put(fieldMap.get(fName).getDescribe().getLabel(), fName);
                    }//if 3    
                }//if 2
            }//for 1
            for (String fLabel:fieldLabels){//for 1
                    options.add(new selectOption(fieldLabelNameMap.get(fLabel),fLabel));
                }//if 2
            }//for 1    
        }//if 1

        return options;



Best Answer chosen by Admin (Salesforce Developers) 

There is an isClosed field, but it's read-only so your code to filter out non-updatable fields is removing it.

All Answers


There is an isClosed field, but it's read-only so your code to filter out non-updatable fields is removing it.

This was selected as the best answer

Thx - that was dumb of me.  I'm an example of the risks of copy & paste code as I ported a method from another org & didn't read it carefully.