1

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:

AND(
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'];

System.assertEquals(false,
    m.FieldDefinition__c != null &&
    m.FieldDefinition__r.DataType != 'Lookup(User)');

Is this yet another bug with custom metadata types?

1 Answer 1

0

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 :)

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.