Tuesday, December 26, 2023

Export all Custom Metadata Records in CSV file using Apex

Using apex, we can export all custom metadata records in CSV files. This is sometime needed if we want to review all custom metadata records after sandbox refresh or to check the dependency of any field or attribute in all custom metadata records.


Below is apex class which can be used for this and once you execute its method from developer console, you will receive email with csv that contain all custom metadata records.

Open developer console and open execute anonymous window. Execute below script:

SK_CustomMetadataUtility.exportAllCMRecordsInCSV();


Below is snapshot of csv file:


Note:

  • This script will specify the custom metadata field api name and its value seperated by "&SK&" delimiter.
  • All fields and its values are seperated by comma.
  • You can modify this method to fetch all custom metadata related to installed packages by specifying a parameter for namespace.


Hope this will help!!

 

22 comments:

  1. 🇧🇷🇮🇴🇻🇬🇧🇳🇰🇭🇧🇮🇧🇫🇧🇬Highly Recommended!
    Very insightful, i will also say this here. Investment is one of the best ways to achieve financial freedom. For a beginner there are so many challenges you face. It's hard to know how to get started. Trading on the Cryptocurrency market has really been a life changer for me. I almost gave up on crypto at some point not until saw a recommendation on Elon musk successfully success story and I got a proficient trader/broker Mr Bernie Doran , he gave me all the information required to succeed in trading. I made more profit than I could ever imagine. I'm not here to converse much but to share my testimony; I have made total returns of $10,500.00 from an investment of just $1000.00 within 1 week. Thanks to Mr Bernie I'm really grateful,I have been able to make a great returns trading with his signals and strategies .I urge anyone interested in
    INVESTMENT to take bold step in investing in the Cryptocurrency Market, you can reach him on WhatsApp : +1(424) 285-0682 or his Gmail : BERNIEDORANSIGNALS@GMAIL.COM, bitcoin is taking over the world, tell him I referred you🇨🇲🇨🇦🇨🇻🇮🇨🇧🇮🇧🇦🇧🇴🇧🇹

    ReplyDelete
  2. Shapoorji Pallonji BKC 28 real estste new design idea all to provide a contemporary and how like living space and enhancing the best skyline.
    Residential quality looking brands focus on high-quality living and offer residential, make luxury commercial, or a great class of new mixed-use areas. The goal of the best project is to provide a thriving with well-planned housing, facilities, and natural environments that best good time help the quality of life.

    https://www.shapoorjipallonji.ind.in/shapoorji-pallonji-bkc-28/

    ReplyDelete
  3. Hello! I recently stumbled upon an informative post that I think you might enjoy reading. Also, have you had a chance to check out the latest stainless steel 410 plates, 347 stainless steel sheet suppliers, and 347h stainless steel sheet? They are definitely worth looking into!

    ReplyDelete
  4. QUICK EASY EMERGENCY URGENT LOANS LOAN OFFER EVERYONE APPLY NOW +918929509036 financialserviceoffer876@gmail.com Dr. James Eric

    ReplyDelete
  5. It was very Nice. This is a great blog I have read.
    #zoopersolutions
    Digital Marketing Agency.

    ReplyDelete
  6. Myron Royal Crest is the next big investment corridor in digwal hyderabad. Invest now and watch your investment grow in the years to come! Myron royal crest with ultra luxury amenities & more options.
    Open Plots In Digwal Hyderabad
    For More Details Contact : 7799949109

    ReplyDelete
  7. MonkTaxSolutions is providing outsourced accounting services with tax preparations & payroll services, etc. Switch to an affordable accounting solution today. Our team will manage the whole process. Our team of professional bookkeepers and accountants provides the services that clients need, with our rates typically 50% less than the equivalent service. Speak to us today!

    Visit - https://monktaxsolutions.com/

    ReplyDelete
  8. Exporting all Custom Metadata Records to a CSV file using Apex involves writing an Apex class to query the Custom Metadata records and then generating a CSV file format from the retrieved data. You can utilize the Metadata namespace and CSVWriter classes for this task. This is a useful approach for migrating metadata configurations or backing up your custom settings.

    And Plz Visit my Website:- Car Transport Quote Services

    ReplyDelete
  9. Your blog has quickly become one of my favorites. The depth and quality of your content are truly impressive. Looking forward to your next post! plan to visit - day outing places in gurugram, papnoghar resort gurgaon is best place for day event near delhi.

    ReplyDelete
  10. This is a great blog I have read. DigitalNewsAlerts
    https://digitalnewsalert.net/

    ReplyDelete
  11. https://digitalnewsalert.net/when-doubled-a-mild-reprimand-intriguing-world-of-crossword-puzzles/

    ReplyDelete
  12. Pedrovazpaulo Executive Coaching
    https://digitalnewsalert.net/pedrovazpaulo-executive-coaching-a-complete-overview/

    ReplyDelete
  13. Vandy Works
    https://digitalnewsalert.net/vandy-works-a-comprehensive-guide-to-their-impact-and-innovation/

    ReplyDelete
  14. Your article is appreciated. Please do more about this title. Thanks

    I am a blogger of gaming, if you're interested you may visit one of my blogs: https://pinaskohan.com/luckywin/

    ReplyDelete
  15. To export all custom metadata records in a CSV file using Apex on Google Cloud Platform, you can utilize the MetadataService class in Salesforce. Below is a simple example of how to do this:

    apex
    Copy code
    public class CustomMetadataExporter {
    public void exportCustomMetadataToCSV() {
    List metadataRecords = [SELECT Field1__c, Field2__c FROM CustomMetadata__mdt];
    String csvContent = 'Field1,Field2\n';

    for (CustomMetadata__mdt record : metadataRecords) {
    csvContent += record.Field1__c + ',' + record.Field2__c + '\n';
    }

    Blob csvBlob = Blob.valueOf(csvContent);
    String fileName = 'CustomMetadataRecords.csv';
    ContentVersion contentVersion = new ContentVersion();
    contentVersion.Title = fileName;
    contentVersion.PathOnClient = fileName;
    contentVersion.VersionData = csvBlob;
    insert contentVersion;
    }
    }
    For more details and advanced options, you can refer to Salesforce documentation and Google Cloud Platform guides. If you need help with coding or dissertation writing services, feel free to ask!

    ReplyDelete
  16. It's incredibly helpful and offers valuable information that I can easily apply. Thnaks!

    ReplyDelete
  17. This Apex script for exporting all custom metadata records into a CSV file is incredibly useful for administrators and developers needing to review metadata post-sandbox refreshes or track dependencies across custom metadata types. It efficiently gathers metadata details, including developer names and custom fields, organizing them into a clear, downloadable format. This tool simplifies compliance checks and enhances transparency in Salesforce configuration management. It's a must-have for maintaining robust Salesforce environments.
    ISO Certification in iraq

    ReplyDelete
  18. This is really a great content. It is really good recommendation. You may also visit my blog, it is about earning gaming app. If you're interested visit here https://megapayaman.ph/winph/

    ReplyDelete
  19. This innovative technology combines convenience with effectiveness, making it a popular choice for pet owners know more. Unlike traditional fences, wireless dog fences offer flexibility and aesthetics, as they do not obstruct views or alter the landscape.

    ReplyDelete