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
- Create Metadata Records in Bulk
- Update Metadata Records in Bulk
- Create Standard & Custom Object Records in Bulk
- 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.
- First Column will always represent the Label for the Custom Metadata
- All the Headers for the `.csv` file will be the Exact API name of the Fields that are associated with the Custom Metadata
- All Date Fields will be having the format `yyyy-mm-dd`
- All DateTime Fields will be having the format
yyyy-mm-dd hh:mm:ss
- All Checkbox Fields will be having the value either `TRUE` or `FALSE`. No 0 or 1
- The maximum length of the Label must be 40 or less
- The label column Can not contain two consecutive underscores
- The label column Can not contain a hyphen (-)
- The label column Can not contain special characters
- 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 🙂
i am an admin, no knowledge about github.
is there be a roadmap available how to install this into a sandbox?
Or perhaps i didnt look well?
Hi David,
Currently, I have not provided any steps but I am planning to provide a way to directly deploy it to the ORG from GitHub
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?
Hi Marin,
I have updated the package and given the Link to Updated Package. Please install the new package again and you will have everything needed.
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.
That component must be available but if you are not able to see check if there is any flow. And also check if the package is available under installed package.
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!
Are you getting any errors under the browser console?
Hi I am getting the same issue. When I select the file and upload it, the spinner just keeps going but nothing happens.
Have you prepared the CSV file in a correct format?
Actually the name is given wrong in metafile, It is given as Custom Metata Uploader. Kindly Correct it in meta file under master label
Changed. Thanks for informing me. Updated the same in code and uploaded the same to package.
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?
Are you able to share the screenshot?
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.
My Bad the code was overwritten. I have uploaded the latest package and the link is there in the blog post.
Unable to attach file here. Please see the screenshot here
https://drive.google.com/file/d/1hOzKp-5wrm3qGqXWA_V8Ax2M-og3zvzb/view?usp=sharing
My Bad the code was overwritten. I have uploaded the latest package and the link is there in the blog post.
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
Hello,
You need to use unique names instead of duplicate. Even Label can be duplicate but hard to identified which label is holding what record. If you make unique it will work.
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?
Are you using a number field in CSV file and then providing the Non Decimal values in it “Does not Expire”. Please check the column list carefully.
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?
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
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.
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
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
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.
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
You have a class name Test inside your org. delete that org and then try again.
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?
Hi leah,
This takes some time as it is deploying the metadata records.
Are the records still not there?
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
Please share the CSV file and Metadata Field Details so that I can check from my side and make the adjustment, Here is the email – sfdcpanther@gmail.com
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
Are you able to shared the csv file sample?
Also, make sure in CSV file there are no spaces in the API Name