{"id":20806900,"url":"https://github.com/agentgill/force-cmdt","last_synced_at":"2026-01-28T21:01:28.719Z","repository":{"id":152507014,"uuid":"391373755","full_name":"agentgill/force-cmdt","owner":"agentgill","description":"Managing \u0026 Testing Custom Metadata","archived":false,"fork":false,"pushed_at":"2021-10-04T09:02:10.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-02T11:49:17.409Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Apex","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/agentgill.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-31T14:08:11.000Z","updated_at":"2021-10-04T09:02:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"504feb25-c239-493b-b955-2454fc533e37","html_url":"https://github.com/agentgill/force-cmdt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/agentgill/force-cmdt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agentgill%2Fforce-cmdt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agentgill%2Fforce-cmdt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agentgill%2Fforce-cmdt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agentgill%2Fforce-cmdt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/agentgill","download_url":"https://codeload.github.com/agentgill/force-cmdt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agentgill%2Fforce-cmdt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28851838,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T15:15:36.453Z","status":"ssl_error","status_checked_at":"2026-01-28T15:15:13.020Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T19:28:15.401Z","updated_at":"2026-01-28T21:01:28.703Z","avatar_url":"https://github.com/agentgill.png","language":"Apex","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Managing \u0026 Testing Custom Metadata\n\nManaging custom metadata \u0026 custom metadata records via the Salesforce UI is tiedious at best, especially if the number of records is large.\n\n**Alternative** - You can build UI using Flow or LWC but you will need to jump through a number of complex Apex hoops using Metadata.CustomMetadat \u0026 Metadata.DeployCallback to get the job done.\n\n**Best Path** - Or you can pull the records into a CSV and use the sfdx-cli to prepare them to be pushed - easy as that\n\n## force:cmdt COMMAND\n\ncreate and update custom metadata types and their records\n\nUSAGE\n\n ```text\n  sfdx force:cmdt:COMMAND\n ```\n\nTOPICS\n\n```bash\n  force:cmdt:field   generate a custom metadata field based on the field type provided\n  force:cmdt:record  create and update custom metadata type records\n```  \n\nCOMMANDS\n\n```bash\n  force:cmdt:create    creates a new custom metadata type in the current project\n  force:cmdt:generate  generates a custom metadata type and all its records for the provided sObject\n```\n\n---\n\n## Baiscs of insert CMT using CLI\n\n### Insert cmdt records using CLI\n\n```bash\nsfdx force:cmdt:record:create -t MyCustomType -n SFDX -l \"Salesforce DX\" Integration__c=sfdx\n```\n\n### Insert cmdt records using CSV\n\n```bash\nsfdx force:cmdt:record:insert -f cmdt.csv -t MyCustomType\n```\n\n### Create new cmdt type\n\n```bash\nsfdx force:cmdt:create -n Token -l \"Crypto Tokens\" -p Tokens -d force-app/main/default/objects     \n```\n\n## Testing Custom Metadata without any Org Dependency\n\nSwitching to an Apex Property and making it testVisible allows for CustomMetadata to be defined and set in the Test Classes (no org dependency) - like magic!\n\n[Apex Class Properties](https://developer.salesforce.com/docs/atlas.en-us.234.0.apexcode.meta/apexcode/apex_classes_properties.htm)\n\n### Example Apex Property Pattern\n\n```java\n   @testVisible\n    public static Map\u003cString, MyCustomType__mdt\u003e getCustomMetadataService {\n        get {\n            if (getCustomMetadataService == null){\n                getCustomMetadataService = new Map\u003cString, MyCustomType__mdt\u003e();\n                for (MyCustomType__mdt cmt : [SELECT MasterLabel,\n                                                    Integration__c\n                                                    FROM MyCustomType__mdt]) {\n                        System.debug(LoggingLevel.INFO, cmt);\n                                                        getCustomMetadataService.put(cmt.MasterLabel, cmt);\n                }\n\n            }\n            System.debug(LoggingLevel.INFO, 'Generating CMT Map using an Apex Class Property');\n            return getCustomMetadataService;\n        }\n        set;\n    }\n```\n\n### Example Apex Test\n\n\n```java\n @isTest\n    static void testCustomMetadataService(){\n\n        // Set my TestVisible getCustomMetadataService using an Automatic Property\n        GetCustomMetadataService.getCustomMetadataService = testCMT;\n\n        Test.startTest();\n        MyCustomType__mdt myCMT = GetCustomMetadataService.getCustomMetadataService.get('Test');\n        System.debug(LoggingLevel.INFO, 'My Custom Metadata record for testing:'+myCMT);\n        Test.stopTest();\n        // Can I assert my Test CustomMetadata?\n        System.assertEquals('Test',myCMT.Integration__c,'Something went wrong!');\n\n    }\n\n \n    private static Map\u003cString, MyCustomType__mdt\u003e testCMT {\n        get {\n            return new Map\u003cString, MyCustomType__mdt\u003e {\n                       'Test' =\u003e ( MyCustomType__mdt ) JSON.deserialize(\n                           '{ \"MasterLabel\" : \"Test\", \"Integration__c\" : \"Test\" }', MyCustomType__mdt.class )\n            };\n        }\n        private set;\n    }\n```\n\n## Read All About It\n\n- [Salesforce Extensions Documentation](https://developer.salesforce.com/tools/vscode/)\n- [Salesforce CLI Setup Guide](https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_intro.htm)\n- [Salesforce DX Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_intro.htm)\n- [Salesforce CLI Command Reference](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference.htm)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagentgill%2Fforce-cmdt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagentgill%2Fforce-cmdt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagentgill%2Fforce-cmdt/lists"}