You need to sign in to do that
Don't have an account?
Vivo
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()); } } }
Avidev9
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.