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
Théo ZANCHIThéo ZANCHI 

get a field name in soql

Hello all, 
I am looking for a SOQL request that could get me both the value and etiquette of a field on a custom object ; is this somehow possible in SOQL?
Thanks in advance
GauravGargGauravGarg
Hi Zanchi,

Yes, we can use Metadata Describe call which can provide us the Custom Object field API name and its value without any query but this works only in VF page Standard Controller. 
 
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
            Schema.SObjectType ObjectSchema = schemaMap.get(CustomObject);

//Retrieve all the fields API names
Map<String, Schema.SObjectField> apiNameValueMap = (CustomObject).getDescribe().fields.getMap();

//Retrieve Fields value, only fields having value in it. 
Map<String, Object> customObjectFilledValues = customObjectControllerInstance.getPopulatedFieldsAsMap()

Hope this will helps you. 

Thanks,
Gaurav
Skype: gaurav62990
Ajay K DubediAjay K Dubedi
Hi Theo,

Do follow this line of code below:

Schema.getGlobalDescribe().get('ObjectName').getDescribe().fields.getMap().get('FieldName').getDescribe().getLabel();

For more information do follow the link as below:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject_describe.htm#apex_methods_system_sobject_describe

Hope you will find this information helpful.

Thanks.
Ajay Dubedi