Toggle Side Panel
Forcetalks
  • Home
  • Articles
    • All Articles
    • Blogs
    • Videos
    • Infographics
  • Consultants
    • Salesforce Product Expertise
      • Top Salesforce ConsultantsTop Salesforce Consultants
    • Salesforce Industry Expertise
    • Salesforce Experts by Location
  • Webinars
  • Contact Us
More options
    Sign in Sign up
    • Home
    • Articles
      • All Articles
      • Blogs
      • Videos
      • Infographics
    • Consultants
      • Salesforce Product Expertise
        • Top Salesforce ConsultantsTop Salesforce Consultants
      • Salesforce Industry Expertise
      • Salesforce Experts by Location
    • Webinars
    • Contact Us
    Close search

    Custom Metadata Test Class Coverage in Salesforce

    manpreet2050
    Manpreet April 16, 2018
    Custom Metadata Test Class Coverage in Salesforce

    When we want to implement custom Logic with IF/ELSE cases then in many scenarios we use Custom Metadata Types. But when we try to cover it in Test Class, its records can’t be inserted like that of a Custom Setting or Custom Object.

    custom-metadata

    You might have stuck in it.Right?

    Assume that we have created:

    # a custom metadata “youMetadata__mdt” with a picklist field on it “Custom_Field__c”;

    # and a custom metadata record with “DeveloperName” value “Default” which we are going to use to determine which calculation to use.

    # Also assume that we have created some simple class singhPortal with the following code:

    1 singhPortal

    ____________

    WORKAROUND :

    ____________

    1.) Create a class MetadataCoverage as shown below :

    2 MetadataCoverage

    2.) Create its Test Class something like this :

    3 MetadataCoverageTest

    3.) Now finally create the Test class for the main class (singhPortal)  i.e singhPortalTest :

    4 singhPortalTest

    The basic test gives 100% coverage. Cheers!!!

    Categories: Salesforce customization
    Tags: Custom Metadata Types, Custom Settings in Salesforce, Metadata Component, Salesforce Custom Objects, Salesforce Customization, Salesforce Records, Test Class in Salesforce

    Get listed your company

    Have an innovative Salesforce solution that delivers faster, smarter results?
    Join the Marketplace

    [adinserter block=”16″]

    best salesforce consultants
    Footer Forcetalks logo

    support@forcetalks.com

    • twitterx

    Quick Links

    Advertise with Us

    Salesforce® Articles

    Dreamforce 2023

    Top Salesforce® Bloggers 2023

    Top Salesforce Consultants

    Get Listed

    Company

    Contact Us

    About Us

    Privacy Policy

    Terms & Conditions

    InsightHub

    Salesforce Blogs

    Salesforce Videos

    Salesforce Groups

    Salesforce Jobs

    Forcetalks

    © 2026 - Forcetalks ● All Rights Reserved

    Salesforce® is a trademark of Salesforce® Inc. No claim is made to the exclusive right to use “Salesforce”. Any services offered within the Forcetalks website/app are not sponsored or endorsed by Salesforce®.