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
VivoVivo 

Using Schema Sobject Field

Hi,

 

I have constructed a dynamic edit/new/view page that gets the fields of an object dynamically based on the id of the object passed in the URL. 

 

When I list out the fields on the visualforce page, it seems as if the order of the fields is random? How is this order chosen?

On the schema builder, the fields are shown in alphabetical order.

 

 Schema.DescribeSObjectResult r1 = sObjType.getDescribe();  
         
          
        Map<String , Schema.SObjectField> mapFieldList = r1.fields.getMap();  
        Integer i = 0;  
        fieldnames='';
        for(Schema.SObjectField field : mapFieldList.values())  
            {  
                Schema.DescribeFieldResult fieldResult = field.getDescribe();  
                fieldnames+=field + ' ,';
                if(fieldResult.isNameField()){
                        namefield= fieldResult.getName();  
                        }
                        else{
                if(fieldResult.isAccessible() && fieldResult.isUpdateable() && !fieldResult.isDefaultedOnCreate())  
                    {  
                        
                   
                        listObjectFields.add(fieldResult.getName());  
                        }
                    }  
                
            
          }    

 

Avidev9Avidev9
Well I guess this is due to Maps, which doesnt maintain the order of contents. Anyways you can always call the "Sort" method on list to sort the item. Or even you can write your own wrapper class to sort the fields.