When creating Custom Metadata entries (especially via API) with relationship fields into other objects, you are limited to certain SObjects that can be used.
The Custom Metadata implementation guide mentions:
The value of a relationship field with the EntityDefinition domain is a custom or standard object that:
• Supports custom fields
• Supports Apex triggers
• Supports custom layouts
• Is not a type of activity, such as a Task or Event
• Is not the User object
• Is not a Trialforce object, such as a SignupRequest
Here I'm asking what is a programmatic way whether an arbitrary SObject is useable in that relationship. The first three requirements doesn't seem to hold water:
SELECT
IsLayoutable,
IsCustomizable,
IsApexTriggerable,
QualifiedApiName
FROM
EntityDefinition
WHERE
QualifiedApiName IN ('Territory2')
Returns true for all fields, but is not valid value. I get INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST: (SObject__c) SObject: bad value for restricted picklist field: Territory2
when deploying via API and it's not available when creating record from UI.
So the question is what other attributes define whether field is relatable?
My code right now is:
@AuraEnabled public static Boolean isObjectRelatable(String sobjectName){
if(String.isEmpty(sobjectName) || sobjectName == 'User' || sobjectName == 'Event' || sobjectName == 'Task'){
return false;
}
Integer count = [SELECT
COUNT()
FROM
EntityDefinition
WHERE
QualifiedApiName =: sobjectName
AND IsLayoutable = TRUE
AND IsCustomizable = TRUE
AND IsApexTriggerable = TRUE
];
return count != 0;
}
I'm not too worried about Trialforce objects at the moment.
IsCustomizable
field which someone else in this site correlated withSupports custom fields
- I am not 100% sure whether that is true.