To know the fields we have to use apex schema programming.You have to use this class Schema.SObjectField here is the detailed documentation link https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_schema.htm
Here is sample page and controller if you select the object then related fields will be displayed.Please save the page and try you will understand clearly. Controller:
public with sharing class DescibeDemoController
{
public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
public String selectedObject {get; set;}
public List<FieldWrapper> listField{get;set;}
public DescibeDemoController()
{
listField = new List<FieldWrapper>();
}
// find all sObjects available in the organization
public List<SelectOption> getListObejectName()
{
List<SelectOption> objNames = new List<SelectOption>();
List<String> entities = new List<String>(schemaMap.keySet());
entities.sort();
for(String name : entities)
objNames.add(new SelectOption(name,name));
return objNames;
}
// Find the fields for the selected object
public void showFields()
{
listField.clear();
Map <String, Schema.SObjectField> fieldMap = schemaMap.get(selectedObject).getDescribe().fields.getMap();
for(Schema.SObjectField sfield : fieldMap.Values())
{
schema.describefieldresult dfield = sfield.getDescribe();
FieldWrapper wObj = new FieldWrapper();
wObj.fieldName = dfield.getLabel ();
wObj.fieldAPIName = dfield.getname();
listField.add(wObj);
}
}
public class FieldWrapper
{
public String fieldName {get; set;}
public String fieldAPIName {get; set;}
}
}
Thanks for your solution. Can you please provide steps after how to execute this apex page. I had saved the apex page and im clueless about the execution part and please provide your POV, if this can be acheived via the query editor?
To know the fields we have to use apex schema programming.You have to use this class Schema.SObjectField
here is the detailed documentation link
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_schema.htm
Here is sample page and controller if you select the object then related fields will be displayed.Please save the page and try you will understand clearly.
Controller:
Apex page:
If it's helpful please make it best answer.
Thanks,
Dilip.
Thanks for your solution. Can you please provide steps after how to execute this apex page. I had saved the apex page and im clueless about the execution part and please provide your POV, if this can be acheived via the query editor?
Regards
Archestain