Determine if field is a component of a compound field

Sometimes there is a need to determine if a field is a component of a compound field.
For example, compound fields components are not permissionable even though field describe isPermissionable method for them returns true. There might be other cases like making correspondence between parts of compound fields and even many more.

There are two tables in Salesforce which correspond to compound fields and its components.

If a field can be found in FieldDefinition table, it is a real (permissionable) field. If a field cannot be found in FieldDefinition table, but can be found in EntityParticle table, it is a part of compound field and not a separate independent field.

If you know DeveloperName of a SObject and DeveloperName of a field, you can use the following query to determine. For example, let’s assume we want to know if standard field MailingStreet on a Contact is a real field or a part of a compound field and also if Geolocation__Latitude__s field on Test__c custom object is a real field or a part of a compound field.

So these two queries will return no results, meaning that these fields are not real fields.

SELECT DurableId FROM FieldDefinition where EntityDefinitionId = 'Contact' AND QualifiedApiName = 'MailingStreet'
SELECT DurableId FROM FieldDefinition where EntityDefinitionId = 'Test__c' AND QualifiedApiName = 'Geolocation__Latitude__s'

Also we can find out all field components for an object using the following query. Let’s assume that we wonder about field components for Contact standard object or Test__c custom object.

SELECT QualifiedApiName, DeveloperName, DurableId FROM EntityParticle where EntityDefinitionId = 'Contact' AND IsComponent = true
SELECT QualifiedApiName, DeveloperName, DurableId FROM EntityParticle where EntityDefinitionId = 'Test__c' AND IsComponent = true

Finally, we can simply make direct queries to find details about these field component using the following queries.

SELECT QualifiedApiName, DeveloperName, DurableId FROM EntityParticle where EntityDefinitionId = 'Contact' AND QualifiedApiName = 'MailingStreet'
SELECT QualifiedApiName, DeveloperName, DurableId FROM EntityParticle where EntityDefinitionId = 'Test__c' AND QualifiedApiName = 'Geolocation__Latitude__s'

Also, another way to determine if a field is component or not is to check field describe getCompoundFieldName method results like following

System.debug(LoggingLevel.ERROR, '@@@ v: ' + Test__c.Geolocation__Latitude__s.getDescribe().getCompoundFieldName() );
System.debug(LoggingLevel.ERROR, '@@@ v: ' + Test__c.Geolocation__c.getDescribe().getCompoundFieldName() );
System.debug(LoggingLevel.ERROR, '@@@ v: ' + Contact.MailingStreet.getDescribe().getCompoundFieldName() );
System.debug(LoggingLevel.ERROR, '@@@ v: ' + Contact.MailingAddress.getDescribe().getCompoundFieldName() );

Hit like if you find this post super awesome.

Advertisements
This entry was posted in apex, field, SOQL. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s