You need to sign in to do that
Don't have an account?
Alvin Tan
How do I get all field names for an object in APEX?
Hi, I'm struggling with getting ALL of the field names for an object in APEX. When running the code below (in APEX), I am getting most of the fields but it's omitting a few contact fields as well as the comment field. When I run the block of code in anonymous apex, all the fields I need are returning. Is there something I might be missing? Thanks in advanced.
Schema.SObjectType targetType = Schema.getGlobalDescribe().get('case'); Map<String, Schema.SObjectField> fieldMap = targetType.getDescribe().fields.getMap(); for (Schema.SObjectField field : fieldMap.values()) { System.debug(field.getDescribe().getName()); }
You wont be able to retrieve the relation fields on the object (lookup etc) using the above methods. It retrives only the standard/custom fields directly present on the object. Please clarify if these are relational fields which are missing?
Regards,
Krishna Avva
I believe you are right that they are relational fields. Would you happen to know a way to dynamically get both relationtional as well as standard/custom fields together? Thanks!
Refer this llink
https://rajvakati.com/2018/10/17/lightning-component-clone-with-related-records/
Hi Alvin,
I hope this will help you to get the fileds name from the Object name:
String SobjectApiName = 'Account';
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Map<String, Schema.SObjectField> fieldMap = schemaMap.get(SobjectApiName).getDescribe().fields.getMap();
for(String fieldName : fieldMap.keyset() )
{
system.debug('fieldName->>'+fieldName); // This will give you the api name of the field name.
}
Thanks