Skip to main content
added 452 characters in body
Source Link
dzh
  • 4.2k
  • 7
  • 52
  • 100

If you DO know the object and field name and just wanna find components of the field, you can use:

public static String[] getComponentFields(String sobjectType, String addressFieldName) {
    EntityParticle[] particles = [
        SELECT QualifiedApiName
        FROM EntityParticle
        WHERE EntityDefinitionId = :sobjectType AND IsComponent = TRUE AND DeveloperName = :addressFieldName
    ];
    String[] ret = new String[]{};
    for(EntityParticle i: particles){
        ret.add(i.QualifiedApiName);
    }
    return ret;
}

Example

Executing:
======================================================================
System.debug(Objects.getComponentFields('Account', 'BillingAddress'));
======================================================================
Success.

14:42:55.120 (197861706)|USER_DEBUG|[1]|DEBUG|(BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry, BillingLatitude, BillingLongitude, BillingGeocodeAccuracy)

If you DO know the object and field name and just wanna find components of the field, you can use:

public static String[] getComponentFields(String sobjectType, String addressFieldName) {
    EntityParticle[] particles = [
        SELECT QualifiedApiName
        FROM EntityParticle
        WHERE EntityDefinitionId = :sobjectType AND IsComponent = TRUE AND DeveloperName = :addressFieldName
    ];
    String[] ret = new String[]{};
    for(EntityParticle i: particles){
        ret.add(i.QualifiedApiName);
    }
    return ret;
}

If you DO know the object and field name and just wanna find components of the field, you can use:

public static String[] getComponentFields(String sobjectType, String addressFieldName) {
    EntityParticle[] particles = [
        SELECT QualifiedApiName
        FROM EntityParticle
        WHERE EntityDefinitionId = :sobjectType AND IsComponent = TRUE AND DeveloperName = :addressFieldName
    ];
    String[] ret = new String[]{};
    for(EntityParticle i: particles){
        ret.add(i.QualifiedApiName);
    }
    return ret;
}

Example

Executing:
======================================================================
System.debug(Objects.getComponentFields('Account', 'BillingAddress'));
======================================================================
Success.

14:42:55.120 (197861706)|USER_DEBUG|[1]|DEBUG|(BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry, BillingLatitude, BillingLongitude, BillingGeocodeAccuracy)
Source Link
dzh
  • 4.2k
  • 7
  • 52
  • 100

If you DO know the object and field name and just wanna find components of the field, you can use:

public static String[] getComponentFields(String sobjectType, String addressFieldName) {
    EntityParticle[] particles = [
        SELECT QualifiedApiName
        FROM EntityParticle
        WHERE EntityDefinitionId = :sobjectType AND IsComponent = TRUE AND DeveloperName = :addressFieldName
    ];
    String[] ret = new String[]{};
    for(EntityParticle i: particles){
        ret.add(i.QualifiedApiName);
    }
    return ret;
}