function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jessica Meyer 1Jessica Meyer 1 

Custom Metadata Type - hitting SOQL limit?

It was my understanding after reading a few different posts and articles like this one that custom metadata types could have unlimited SOQL queries in a single Apex transaction. To give you an idea of the code that I'm using, it's designed to find a set of values (stored in custom metadata) to apply to an opportunity based off of some criteria pulled from the opp. When I tried to run this to update opps in bulk, it failed on the SOQL query error. My query:
List<Channel_Discount__mdt> chanSetting = [SELECT Direct__c,Fulfillment__c,Authorized__c,Certified__c,Regions__c,Excluded_Countries__c FROM Channel_Discount__mdt WHERE Discount__c = :w AND Distributor_Type__c = :distType AND Business_Type__c = :bisType];

Am I misunderstanding what is meant by "unlimited" queries?
Best Answer chosen by Jessica Meyer 1
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello Prashant and Jessica,

Custom Metadata and Custom Setting are different features of the Salesforce Platform. 

Jessica - You're right! It shouldn't count against the limit but there is an exception. When you query a long text area field from a metadata it does counts against the limits, please, check if that is your case. If not, check whether or not, another SOQL is affecting your limits if there is any.

User-added image
https://help.salesforce.com/articleView?id=custommetadatatypes_limits.htm&type=5 (http://​https://help.salesforce.com/articleView?id=custommetadatatypes_limits.htm&type=5)

Prashant - You're also right in saying that is better to retrieve Custom Settings using its classes but Jessica mentioned a Custom Metadata and not a Custom Setting. Custom metadata is retrieved by using SOQL queries.

Hope to have helped!

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.

All Answers

Jessica Meyer 1Jessica Meyer 1
I should clarrify that the error is your typical "System.LimitException: Too many SOQL queries: 101 error" but when run in small batches of opportunity updates it works just fine.
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello Prashant and Jessica,

Custom Metadata and Custom Setting are different features of the Salesforce Platform. 

Jessica - You're right! It shouldn't count against the limit but there is an exception. When you query a long text area field from a metadata it does counts against the limits, please, check if that is your case. If not, check whether or not, another SOQL is affecting your limits if there is any.

User-added image
https://help.salesforce.com/articleView?id=custommetadatatypes_limits.htm&type=5 (http://​https://help.salesforce.com/articleView?id=custommetadatatypes_limits.htm&type=5)

Prashant - You're also right in saying that is better to retrieve Custom Settings using its classes but Jessica mentioned a Custom Metadata and not a Custom Setting. Custom metadata is retrieved by using SOQL queries.

Hope to have helped!

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
This was selected as the best answer
Jessica Meyer 1Jessica Meyer 1
Thank you Zuinglio! That is EXACTLY what the problem was in the this case. I appreciate the help!