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
kailash chandrakailash chandra 

create test class to insert metadata record

I need the 100% code coverage of this code, Where I am retrieving records from custom metadata. So I need to insert metadata through test class.
Please help me.
public class GenerateAccess{
    public Map<String,String> revokeAccess(String realmId){
        Map<String,String> rtrnMap=new Map<String,String>() ;
        String errorString='';    
        List<Token__mdt> tokens=new List<Token__mdt>([Select DeveloperName,MasterLabel,Access_Token__c,Sandbox_Client_Id__c,Sandbox_Client_Secret__c,Refresh_Token_Expires_in__c,Realm_Id2__c from Token__mdt where Realm_Id2__c=:realmId Limit 1]);
            String encodedString = EncodingUtil.base64Encode(Blob.valueOf(to[0].Sandbox_Client_Id__c+':'+tokens[0].Sandbox_Client_Secret__c));
AnudeepAnudeep (Salesforce Developers) 
Hi Kailash, 

The examples in the following blogs might help

Also if you want to better understand how custom metadata types behave in Apex tests refer to Testing Custom Metadata Types