0

Awhile ago, I was given a SOQL query that would retrieve the fields of a given object:

SELECT Label, QualifiedApiName FROM FieldDefinition WHERE EntityDefinition.QualifiedApiName = 'ObjectName'

I am extremely thankful for this, however for compound fields, the results only seem to capture the name of the compound field and not its contents.

For example, if I use "Account", it will retrieve "Billing Address" and "Shipping Address", but not "Billing City", "Billing Country", "Shipping City", etc.

Is there a way to get these items from a SOQL query? Even if it requires a separate query, that'd be ok.

1 Answer 1

2

This query will get all the components of a single compound field:

SELECT Label, QualifiedApiName FROM EntityParticle WHERE EntityDefinition.QualifiedApiName = 'ObjectName' AND IsComponent = TRUE AND DeveloperName = 'AddressFieldName'

However, you can get all fields on an object in one query, including compound fields and their components by querying the EntityParticle object:

SELECT Label, QualifiedApiName FROM EntityParticle WHERE EntityDefinition.QualifiedApiName = 'Account'

This is the result for Account:

enter image description here

1
  • 1
    Fantastic answer as always @fred Commented Aug 21, 2023 at 17:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .