Toggle Side Panel

  • Home
  • Articles
    • All Articles
    • Blogs
    • Videos
    • Infographics
  • Consultants
    • Salesforce Product Expertise
      • Top Salesforce ConsultantsTop Salesforce Consultants
      • Marketing Cloud ConsultantsMarketing Cloud Consultants
      • Service Cloud ConsultantsService Cloud Consultants
      • Experience Cloud ConsultantsExperience Cloud Consultants
      • Analytics Cloud ConsultantsAnalytics Cloud Consultants
    • Salesforce Industry Expertise
      • Non-Profit Cloud ConsultantsNon-Profit Cloud Consultants
      • Financial Service Cloud ConsultantsFinancial Service Cloud Consultants
      • Health Cloud ConsultantsHealth Cloud Consultants
      • Commerce Cloud ConsultantsCommerce Cloud Consultants
      • Manufacturing Cloud ConsultantsManufacturing Cloud Consultants
    • Salesforce Experts by Location
      • USATop Salesforce Consultants in USA
      • IndiaTop Salesforce Consultants in India
      • AustraliaTop Salesforce Consultants in Australia
      • United KingdomTop Salesforce Consultants in UK
      • CanadaTop Salesforce Consultants in Canada
  • Webinars
  • Contact Us
  • Discussions
More options
    Sign in Sign up
    • Home
    • Articles
      • All Articles
      • Blogs
      • Videos
      • Infographics
    • Consultants
      • Salesforce Product Expertise
        • Top Salesforce ConsultantsTop Salesforce Consultants
        • Marketing Cloud ConsultantsMarketing Cloud Consultants
        • Service Cloud ConsultantsService Cloud Consultants
        • Experience Cloud ConsultantsExperience Cloud Consultants
        • Analytics Cloud ConsultantsAnalytics Cloud Consultants
      • Salesforce Industry Expertise
        • Non-Profit Cloud ConsultantsNon-Profit Cloud Consultants
        • Financial Service Cloud ConsultantsFinancial Service Cloud Consultants
        • Health Cloud ConsultantsHealth Cloud Consultants
        • Commerce Cloud ConsultantsCommerce Cloud Consultants
        • Manufacturing Cloud ConsultantsManufacturing Cloud Consultants
      • Salesforce Experts by Location
        • USATop Salesforce Consultants in USA
        • IndiaTop Salesforce Consultants in India
        • AustraliaTop Salesforce Consultants in Australia
        • United KingdomTop Salesforce Consultants in UK
        • CanadaTop Salesforce Consultants in Canada
    • Webinars
    • Contact Us
    • Discussions
    Close search
    metadata api

    Understanding Metadata API in Salesforce | The Developer Guide

    Ayush Jul 9, 2020
    21,551  Views

    Metadata API

    Salesforce Metadata API is utilized to help designers in retrieving, creating, deploying, updating, or deleting the customized information. It can be something that uses custom object definitions and page layouts for Salesforce organizations. The new Apex Metadata API makes it possible to build equipment to manipulate the metadata version, in preference to the records itself.

    The most straightforward approach to get to the usefulness in Metadata API is to utilize the Salesforce Extensions for Visual Studio Code or the Ant Migration Apparatus. The two devices are based on the Metadata API and utilize the standard apparatuses to streamline working with Metadata API. 

    dont miss out iconDon’t forget to check out: An Introduction to Salesforce Force.com Migration Tool (ANT)

    • The Salesforce Extensions for Visual Studio Code remembers apparatuses for producing for the Salesforce stage in the lightweight, extensible VS Code editorial manager. These instruments furnish highlights for working with improvement organizations (scratch organizations, sandboxes, and DE organizations), Apex, Aura parts, and Visualforce. 
    • The Ant Migration Tool is perfect on the off chance that you utilize content or the order line for moving metadata between a nearby registry and a Salesforce organization.

    When you work in a multi-org environment. Saying you have 20 orgs, one for each of the states in which you do business. You use managed packages to update the orgs. You have created a custom field for Contact, and you want it to show up on the UI (page layout) in all your orgs. This problem can be solved with the help of metadata API.

    How to Get Web Service WSDLs For Your Salesforce Organization

    • Step1:   Login into your org Account 
    • Step2: Go to Setup, enter API in the Quick Find box, then select API. 
    • Step3:  Click Generate Metadata WSDL  & Enterprise WSDL and save the XML WSDL file to your system.
    • Step4:  Next go to Quick Find box and enter Apex Class 
    • Step5:  Convert WSDL to Apex ( there is a button )

    How To Create Custom Object And Custom Fields Through Metadata API

    Ex.

    public static void createObject()
    {
        MetadataService.MetadataPort service = createService();
        MetadataService.CustomObject customObject = new MetadataService.CustomObject();
        customObject.fullName = 'Test__c';
        customObject.label = 'Test';
        customObject.pluralLabel = 'Tests';
        customObject.nameField = new MetadataService.CustomField();
        customObject.nameField.type_x = 'Text';
        customObject.nameField.label = 'Test Record';
        customObject.deploymentStatus = 'Deployed';
        customObject.sharingModel = 'ReadWrite';
        List<MetadataService.SaveResult> results =
        service.createMetadata(new MetadataService.Metadata[] { customObject });
    }
    public class Createfield_mdt {
        public static void createField(String objectName , String fieldName){
            MetadataService.MetadataPort service = createService();
            MetadataService.CustomField customField = new MetadataService.CustomField();
            customField.fullName = objectName+'.'+fieldName+'__c';
            customField.label = fieldName;
            customField.type_x = 'Text';
            customField.length=20;
            service.createMetadata(new MetadataService.Metadata[] { customField });       
        }   
        public static void CreateLookupField (String objectName , String fieldName){
            MetadataService.MetadataPort service = createService();
            MetadataService.CustomField customField = new MetadataService.CustomField();
            customField.fullName = objectName+'.'+fieldName+'__c';
            customField.label = fieldName;
            customField.type_x = 'Lookup';
            customField.relationshipLabel = objectName;
            customField.relationshipName = objectName;
            customField.referenceTo = 'Opportunity';
            service.createMetadata(new MetadataService.Metadata[] { customField });
        }  
        public static MetadataService.MetadataPort createService() {
            MetadataService.MetadataPort service = new MetadataService.MetadataPort();
            service.SessionHeader = new MetadataService.SessionHeader_element();
            service.SessionHeader.sessionId = UserInfo.getSessionId();
            return service;
        }
    }

    dont miss out iconCheck out another amazing blog by Ayush here: What Is Custom Metadata type In Salesforce – All You Need to Know

    Limitations of Metadata API

    We can not perform delete operation, only read, create, and updates are supported. Metadata API using an asynchronous deploy, which is not compatible with Asynchronous tests.

    Reference: trailhead.salesforce, marketplace.visualstudio

    Categories: Coding and Scripting
    Tagged: Asynchronous Tests, Aura Parts, Custom Fields, custom object, Enterprise WSDL, Metadata API, Metadata Version, Salesforce, Salesforce Extensions, Salesforce Metadata API, Salesforce Organization, Visual Studio Code, Visualforce, Web Service, WSDLs, XML WSDL

    Get listed your company

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

    [adinserter block=”16″]

    best salesforce consultants
    best salesforce consultants
    best salesforce consultants
    salesforce consultants

    [adinserter block=”10″]

    salesforce consultants

    [adinserter block=”10″]

    salesforce consultants

    [adinserter block=”10″]

    salesforce consultants

    [adinserter block=”10″]

    salesforce consultants
    salesforce consultants

    [adinserter block=”10″]

    salesforce consultants
    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

    © 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®.

    Try AuditMyCRM - It is a Salesforce CRM Audit tool which comprehensively scans your Salesforce org and gives you the list of errors or warnings you need to take care of.
    We use cookies to enhance your browsing experience. Please see our privacy policy if you'd like more information on our use of cookies.