6

When I query string columns on custom metadata objects, I get decent performance. However, if I query a column that points to a FieldDefinition, my query became much slower.

Is this a known system bug? Is there a patch on the horizon?

It makes these relationships really unusable.

Here are profiling logs on a sandbox. (I'll just include the SOQL profiling.):

Querying a String takes 19ms.

for (My_Metadata__mdt m: [SELECT Id, String__c FROM My_Metadata__mdt]) {
    System.debug(m.id);
}
AnonymousBlock: line 1, column 1: [SELECT Id, String__c FROM My_Metadata__mdt]: executed 273 times in 19 ms

Query a FieldDefinition takes about half a second!

for (My_Metadata__mdt m: [SELECT Id, Field__c FROM My_Metadata__mdt]) {
    System.debug(m.id);
}
AnonymousBlock: line 1, column 1: [SELECT Id, Field__c FROM My_Metadata__mdt]: executed 273 times in 511 ms

Profiling Procedure:

  1. Run a snippet ~10 times.
  2. Note the times on each except the first are about the same.
  3. Choose one of the middle-ground non-first logs to paste here.
4

1 Answer 1

0

5 years later and the same difference in speed can still be measured - I've just given it a try :-)

But things have improved, and the obvious answer to the question raised by the title is: not to query the database, but to access the application cache by the methods provided by the "Custom Metadata Type" object.

The loop could then look like this:

for (My_Metadata__mdt m: My_Metadata__mdt.getAll().values()) {
    System.debug(m.Field__c);
}

My tests indicate this is indeed faster than any of the afore SOQL.

You must log in to answer this question.

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