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
Balakrishna RaoBalakrishna Rao 

Is there a way in apex to determine whether the field is standard field or custom field in dynamic apex

i have few things to ask
1) is there way in apex to generate all custom field in apex for a particular object.
2) In dynamic apex is there a way to check the field is standard field or custom field
AbhinavAbhinav (Salesforce Developers) 
Hi Balakrishna,

I think this will work:
 
String apiName='Account';
    SObjectType objType = ((SObject) (Type.forName('Schema.' + apiName).newInstance())).getSObjectType();
    Map<String, SObjectField> fieldsByName = objType.getDescribe().fields.getMap();
    List<String> customFields = new List<String>();

    for (SObjectField field : fieldsByName.values()) {
        if (field.getDescribe().isCustom()) {
            customFields.add(field.getDescribe().getName());
        }
    }

    System.debug('customFields => ' + customFields);

reference:

https://salesforce.stackexchange.com/questions/270732/how-to-get-list-of-custom-fields-using-dynamic-apex

If it helps mark it as best answer.

Thanks!
Jay MandalJay Mandal
1. To generate all fields in apex
To fields of Account object
Map<String,Schema.SObjectField > fieldmap=Schema.SObjectType.Account.fields.getmap();

OR  dynamically you can generate  field for any object
Map<String,Schema.SObjectField > fieldmap= ((SObject) Type.forName(sobjName)
        .newInstance())
      .getSObjectType()
      .getDescribe()
      .fields.getMap();
2.Check if fields is custom or standard
Schema.DescribeFieldResult dfr = Account.Description.getDescribe();
Boolean iscustomField=dfr.isCustom();
Or you can use

Schema.SObjectField field= ((SObject) Type.forName(
          objName
        )
        .newInstance())
      .getSObjectType()
      .getDescribe()
      .fields.getMap()
      .get(FieldName);
Boolean iscustomField=field.getDescribe().isCustom();
Please Mark this as best answer.