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
VSK98VSK98 

How to insert the custom meta datatype in test class

Hi All,

I am using custom metadata type in Apex class. I am trying to insert the custom metadata type like custom object but I am getting an error. the fields are not editable. 

In Apex Class:
Roles__mdt roles = [SELECT id,Name from Roles__mdt where Name__c = 'xxxx' AND Isactive__c = true]

Adv thanks,
VSK98
Rajesh3699Rajesh3699
Hi,

No need to create test records for MetaData,

Thank You,
Rajesh Adiga P.
Deepali KulshresthaDeepali Kulshrestha
Hi VSK98,

It is not possible to insert test custom metadata, unless you use the Metadata API which would also present a challenge in a test scenario. That said, you should not need to. Custom Metadata is Metadata and as such is not affected by the SeeAllData annotation. See this article dedicated to testing custom metadata.

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha