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
Abhi CharlesAbhi Charles 

Can we find al custom fields

We have a requirement where we need to show all the custom field on a visualforce page , now what exactly is the issue that I do not know what all are the custom fields in that particular object. This is something like creating a product and giving it to the user, now whenever that user uses the functionality of this product through some button a pop appears where he has the ability to select standard and custom filed of that object. While developing this product we cannot hardcode anything. Therefore I was looking for any help so that I can show all the custom field of that particular object on my visual force page. Any help is highly appreciated.

Best Answer chosen by Admin (Salesforce Developers) 
Vishal GuptaVishal Gupta

Hey charles,
As far i understood ur problem u dont wana harcode the display of ur all custom fields on VF page.U just want it to be dynamic,either a new field is added or removed ur VF must display as per that....If this is the case u can use describe call on that object and get a MAP of all the custom fields including standard and custom as well.

 

Map<String,Schema.SObjectType> Schemaap = Schema.getGlobalDescribe();
transient Schema.DescribeSobjectResult arbdsr = Schemaap.get('object name').getDescribe();
Map<String,Schema.SobjectField> fieldMap = arbdsr.fields.getMap();

 

It will return a map with all the fields...

If it helped kindly mark it as a solution..thanks 

All Answers

Vishal GuptaVishal Gupta

Hey charles,
As far i understood ur problem u dont wana harcode the display of ur all custom fields on VF page.U just want it to be dynamic,either a new field is added or removed ur VF must display as per that....If this is the case u can use describe call on that object and get a MAP of all the custom fields including standard and custom as well.

 

Map<String,Schema.SObjectType> Schemaap = Schema.getGlobalDescribe();
transient Schema.DescribeSobjectResult arbdsr = Schemaap.get('object name').getDescribe();
Map<String,Schema.SobjectField> fieldMap = arbdsr.fields.getMap();

 

It will return a map with all the fields...

If it helped kindly mark it as a solution..thanks 

This was selected as the best answer
Vishal GuptaVishal Gupta
Hi pradeep, i dint completely understood ur solution,so sry for that. But i wana say to charles that i hv used the method that i gave and its concise and good.

Hope its useful for him.