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
jkucerajkucera 

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(u.ObjectName__c!=null){
            evaluateFields=True;
        }
 
        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
                if(fieldMap.get(fName).getDescribe().getType()!=Schema.DisplayType.anytype&&fieldMap.get(fName).getDescribe().getType()!=Schema.DisplayType.base64&&fieldMap.get(fName).getDescribe().getType()!=Schema.DisplayType.EncryptedString&&fieldMap.get(fName).getDescribe().getType()!=Schema.DisplayType.Id&&fieldMap.get(fName).getDescribe().getType()!=Schema.DisplayType.MultiPicklist&&fieldMap.get(fName).getDescribe().getType()!=Schema.DisplayType.Reference&&fieldMap.get(fName).getDescribe().getType()!=Schema.DisplayType.TextArea){
                    //Disallow fields that aren't updatable
                    if(fieldMap.get(fName).getDescribe().isUpdateable()==True){
                        fieldLabels.add(fieldMap.get(fName).getDescribe().getLabel());                  
                        fieldLabelNameMap.put(fieldMap.get(fName).getDescribe().getLabel(), fName);
                    }//if 3    
                }//if 2
            }//for 1
            fieldLabels.sort();
            for (String fLabel:fieldLabels){//for 1
                    options.add(new selectOption(fieldLabelNameMap.get(fLabel),fLabel));
                }//if 2
            }//for 1    
        }//if 1

        return options;
    }//getFieldNames

 

 

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

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

All Answers

SuperfellSuperfell

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
jkucerajkucera

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.