How to import custom metadata records in Salesforce?

on

|

views

and

comments

Hello Everyone,

Welcome back! In this post, we are going to talk about how we can import the Custom Metadata Records in Salesforce Using Lightning Web Component/Flow Builder and Apex.

Full Code

You can get the Complete code from Here

Features of the Solution

  1. Create Metadata Records in Bulk
  2. Update Metadata Records in Bulk
  3. Create Standard & Custom Object Records in Bulk
  4. Use LWC or Lightning Flow Builder to Upload the Metadata

Installation Links

Production Installation Link

https://login.salesforce.com/packaging/installPackage.apexp?p0=04t4x000000qGIk

Sandbox Installation Link

https://test.salesforce.com/packaging/installPackage.apexp?p0=04t4x000000qGIk

Post Installation Step ( Required )

After you have installed the application, you need to assign the “Custom Metadata Uploader Permission Set” Permission set to all the users who will be using this solution.

Prepare CSV File

To use this solution all you need is to prepare a .csv file

Tips to prepare CSV file

To prepare the .csv file you need to keep the below things in your mind.

  1. First Column will always represent the Label for the Custom Metadata
  2. All the Headers for the `.csv` file will be the Exact API name of the Fields that are associated with the Custom Metadata
  3. All Date Fields will be having the format `yyyy-mm-dd`
  4. All DateTime Fields will be having the format yyyy-mm-dd hh:mm:ss
  5. All Checkbox Fields will be having the value either `TRUE` or `FALSE`. No 0 or 1
  6. The maximum length of the Label must be 40 or less
  7. The label column Can not contain two consecutive underscores
  8. The label column Can not contain a hyphen (-)
  9. The label column Can not contain special characters
  10. The label column Can not contain the duplicate rows in the file

To use the Lightning Web Component you can drag & drop 

`Custom MetaData Uploader` component to the home page and then you can select your metadata, 

browse the `.csv` and then click on the upload button.
Here is the sample screenshot

#OutPut

Sample File

Find attached the sample files for Account Object and Countries metadata

Thanks for reading 🙂

Amit Singh
Amit Singhhttps://www.pantherschools.com/
Amit Singh aka @sfdcpanther/pantherschools, a Salesforce Technical Architect, Consultant with over 8+ years of experience in Salesforce technology. 21x Certified. Blogger, Speaker, and Instructor. DevSecOps Champion
Share this

Leave a review

Excellent

SUBSCRIBE-US

Book a 1:1 Call

Must-read

How to Utilize Salesforce CLI sf (v2)

The Salesforce CLI is not just a tool; it’s the cornerstone of development on the Salesforce Platform. It’s your go-to for building, testing, deploying, and more. As one of the most important development tools in our ecosystem

Save the day of a Developer with Apex Log Analyzer

Table of Contents What is Apex Log Analyzer? Apex Log Analyzer, a tool designed with Salesforce developers in mind, is here to simplify and accelerate your...

Salesforce PodCast

Introduction Hey Everyone, Welcome to my podcast, the first-ever podcast in India for Salesforce professionals. Achievement We are happy to announce that we have been selected as Top...

Recent articles

More like this

42 COMMENTS

  1. This looks like exactly what I need, but when I install the managed package into my sandbox org, I can’t find any of the components. There doesn’t seem to be a permission set in here, so I can’t even get past that step.Am i missing something?

  2. Hi SFDC Panther! Thank You for your efforts. I”ve installed ver 1.3 of the package. The installation was claimed successful, but also i have see that CustomMetaDataUploader Lightning Web Component Bundle was installed I cannot see this component when I edit Home page.

  3. Hi there!
    I have installed the package into my sandbox & assigned the permissions to myself. I selected the Metadata, uploaded a file and when I click Upload Metadata, I get the spinner, but nothing happens. The spinner just keeps going.
    I made sure that pop-ups and notifications are allowed (in case I needed to authorize anything). Please let me know if there is something else that I need to do to enable this to work. Thanks!

  4. Actually the name is given wrong in metafile, It is given as Custom Metata Uploader. Kindly Correct it in meta file under master label

  5. Hi Amit, I have installed the package in a sandbox, assigned the permission set to my user and added the component to the home page. The component on the home page allows me to select the file, but the option to select the Metadata isn’t there. Did I miss a step?

  6. Same issue is with me. The component on the home page allows me to select the file, but the option to select the Metadata isn’t there.

    • Like the previous comment, If you could share the image of your home page and for the console then only I can help as I have tested for 10+ orgs and it is working for me.

      One thing that I could sense is that You do not have access to Custom Metadata object at your profile level and if you are an admin then please do share the screenshots

      • I’m experiencing the same – The component on the home page allows me to select the file, but the option to select the Metadata isn’t there. Not sure how to share a screen shot but you can imagine it appearing exactly as your component does above but without the metadata selector dropdown. I am an admin and can confirm I’ve got permissions to the object in question, and others. It’s just the selector is not appearing.

  7. Hi I am getting this error saying FATAL_ERROR System.HandledException: Cannot deploy metadata with duplicate fullName Countries__mdt.Argentina for entities of type: CustomMetadata. But Most of my meta data label have duplicate names, it will be better to include Name_c field instead of Label

  8. I really hope we can get this to work, setup was a breeze, however, I am trying to upload the .mdt records now but getting this error:
    {“status”:500,”body”:{“exceptionType”:”System.TypeException”,”isUserDefinedException”:false,”message”:”Invalid decimal: Does not Expire”,”stackTrace”:”Class.CustomMetadataUploader.popupateValues: line 199, column 1\nClass.CustomMetadataUploader.createCustomMetadataCSVRecords: line 95, column 1\nClass.CustomMetadataUploader.uploadFile: line 70, column 1″},”headers”:{}}

    Can you help with that error?

      • Within the Custom MetaData object, the field it’s erroring on is a Picklist field. Somehow your code is reading that as a Number field and expecting a decimal when it’s actually getting text that matches the picklist values for that field.

        • The code is correct. I have checked it again. Make sure you have followed all the steps to prepare the CSV file. Also, do you have any number field lect or right to your picklist?

          The problem is with the CSV file. Are you able to share the screenshot?

  9. I received a couple errors that I fixed myself, but now I’m running into an issue where it will just spin and not do anything once I click “Upload Metadata”. It’s a file of 1,100 records if that makes an difference – if I need to split it into smaller chunks, that works. I just wasn’t sure if there’s a limitation that I am unaware of?

    • What were the issues that you have fixed?

      Also, let me test with the no of records that you have mentioned. However the limit I know is 250 records I belive. Still I will confirm

  10. hi, when i try to upload a CSV, the spin is just turning all day long and nothing else happened (i’ve followed all of your step and i’m admin).
    Thanks

    • Share the screenshot of the CSV file and make sure your Label Column does not contain any of the following
      The maximum length must be 40 or less
      Can not contain two consecutive underscores
      Can not contain a hyphen (-)
      Can not contain special characters
      Can not contain the duplicate rows in file

      As people are not preparing the file correctly you will get into the issue.

  11. Hi, and thank you very much for this utility. It’s a life saver.
    I have been using this once already, but now, I can’t access the sample files, and for some reason, when I create my own, I get an index out of bounds error.

    Can you please resubmit/share sample CSV files?

    I will try to see where the issue is

  12. I found another tip to add to the CSV build.
    Do not end the line/file with a comma.

    So, last column, must have values populated.

    That solved my issue
    Thank you

  13. exceptionType”:”System.HandledException”,”isUserDefinedException”:false,”message”:”Cannot deploy metadata with duplicate fullName Lead_Source_Mapping__mdt.LinkedIn for entities of type: CustomMetadata”,”stackTrace”:”Class.CustomMetadataUploader.deployCustomMetadataRecord: line 168, column 1\nClass.CustomMetadataUploader.deployCustomMetadataRecord: line 168, column 1\nClass.CustomMetadataUploader.createCustomMetadataCSVRecords: line 107, column 1\nClass.CustomMetadataUploader.uploadFile: line 70, column 1″},”headers”:{}}

    After getting an exception, just noticed that the tool does not support any duplicate rows. We’ve one of the column in our Custom Metadata that may have duplicate values.

    1/5 for user interface. Given it is for Custom Metadata, it shows you the whole bunch of Objects also.
    Sorry, but a waste of time for us. Need a lot of improvement. The idea is good but all the use cases haven’t been considered to develop this tool.

    • The utility is not only for custom metadata it is for custom and standard objects as well.

      Regarding the error, it clearly says that there are duplicate fullName and that is expected because there can not be 2 metadata records with the same name.

      Why should the tool accept duplicate values?

      If you have some features that need to be added then please add those here but do not blame your mistakes to the tool as this is still in initial versions.

      The blog post clearly states the points that need to be taken care of.

      I do know about your issue but this tool has helped many people and save a lot time.

  14. This package can’t be installed.
    There are problems that prevent this package from being installed.
    Method does not exist or incorrect signature: void isRunningTest() from the type Test
    CustomMetadataUploader: Method does not exist or incorrect signature: void isRunningTest() from the type Test
    Dependent class is invalid and needs recompilation: Class CustomMetadataUploader : Method does not exist or incorrect signature: void isRunningTest() from the type Test
    CustomMetadataUploaderController: Dependent class is invalid and needs recompilation: Class CustomMetadataUploader : Method does not exist or incorrect signature: void isRunningTest() from the type Test

  15. Hi, first time using this tool. I tried several times to import a file and got errors, which I believe I corrected.
    The last time I only got errors on 2 rows instead of the whole file.
    But I don’t see that anything happened or any records were created in the meta data.

    Does that mean there is still an issue with the file? Does it take a while for the job to run?

  16. I’m receiving the same error as in an earlier post. I have made sure that my column headers are in line with the instructions and there are no duplicate labels. I have also used Label and MasterLabel as column headers and neither work. The file contains 6 columns: Label, one text field, and four picklists that contain record ID values. Any insight into why this error keeps popping?

    Error:
    {“status”:500,”body”:{“exceptionType”:”System.ListException”,”isUserDefinedException”:false,”message”:”List index out of bounds: 2″,”stackTrace”:”Class.CustomMetadataUploader.createCustomMetadataCSVRecords: line 85, column 1\nClass.CustomMetadataUploader.uploadFile: line 70, column 1″},”headers”:{}}

    File Column Headers
    Label Approver_Details__c Integra_Connect_Level_1__c Integra_Connect_Level_2__c Omega_Level_1__c Omega_Level_2__c

  17. Trying to upload and getting the following error: Custom Metadata Record Name: The Zip Code API Name can only contain underscores and alphanumeric characters. It must be unique, begin with a letter, not include spaces, not end with an underscore, and not contain two consecutive underscores.

    My first column header is : Zip Code
    API name is: Zip_Code__mdt
    I don’t see a way to change the API name for the custom metadata label’s API name
    Any help would be greatly appreciated

LEAVE A REPLY

Please enter your comment!
Please enter your name here

5/5

Stuck in coding limbo?

Our courses unlock your tech potential