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
AjamAjam 

How to extract list of fields

Is there any tool(like example Ajax tool etc) to extract the list of fields in opportunity for a particular record type

 

or

 

Is there any other way, simpler way of extracting that manually ?

adamproadampro

In what context are you trying to do this? I recently wrote a function for a visualforce page that compiles a list of all the fields of a select object. 

 

In the code below, objectChoice is the API name of the object whose fields you are trying to find.

 

 

public list<SelectOption> getDependentCall() {
        List <SelectOption> options = new List<SelectOption>();
        List <SelectOption> allFields = new List <SelectOption>();
        
        if (objectChoice != Null) {
            Map<String, Schema.SobjectType> gdMap = Schema.getGlobalDescribe();
            Schema.DescribesObjectResult dor = gdMap.get(objectChoice).getDescribe();
            Map<String, Schema.SObjectField> fieldMap = dor.fields.getMap();
            list<Schema.SObjectField> sot = dor.fields.getMap().Values();
            map<string, Schema.SObjectField> tempFieldDescribeMap = new Map<String, Schema.SObjectField>();
            
            for(Schema.SobjectField f : sot) {
                Schema.DescribeFieldResult fdescribe = f.getDescribe();
                tempFieldDescribeMap.put(fdescribe.getName(), f);
                allFields.add(new SelectOption(fdescribe.getName(), objectChoice + '> ' + fdescribe.getLabel()));
                list <Schema.sObjectType> typeList = fdescribe.getReferenceTo();
                
                if (typeList.size() > 0) {
                    Schema.SObjectType sotype = typeList[0];
                    Schema.DescribeSObjectResult dsor = sotype.getDescribe();
                    
                    if (dsor.getLabel() == 'User') {
                        options.add(new SelectOption(fdescribe.getName(), fdescribe.getLabel()));
                    }
                }
            }
            fieldList = allFields.clone();
            fieldDescribeMap = tempFieldDescribeMap.clone();
        }
        
        else {
            options.add(new SelectOption('Null', 'Please select an object first.' ));
        }
        
        return options;
    }

 

 

Hope this helps!