A custom metadata type has a Field Definition related to an Entity. The following validation rule ensures the value of this field can only be a User lookup:

FieldDefinition__c != NULL,
FieldDefinition__r.DataType != 'Lookup(User)')

When trying to create a record with Field Definition set to a User lookup field the validation rule causes an error - incorrectly.

However, the following Apex block passes - correctly:

Custom__mdt m = [SELECT FieldDefinition__r.DataType FROM Custom__mdt WHERE Id = 'm003h0000011eBi'];

    m.FieldDefinition__c != null &&
    m.FieldDefinition__r.DataType != 'Lookup(User)');

Is this yet another bug with custom metadata types?

1 Answer 1


Ah dang, you're right.

So the Formula Context that Validation Rules for custom metadata record saves is...a bit weird. And indeed, as I look at it, the DataType we process in the Formula context is not the same information as what goes through the SOQL engine. Specifically, we don't include what the target of the relationship is (e.g. the (User) part).

To get you a known issue, you'll need to file a case. Once you have a case number, comment here and we'll get it fast tracked direct to engineering.

signed, a member of the custom platform team :)

  • Thanks for confirming. Just logged the case thru partner community: 27676712
    – Mossi
    Sep 23, 2020 at 20:36

You must log in to answer this question.

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