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
  • Marketplace
  • Advertise With Us
  • 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
    • Marketplace
    • Advertise With Us
    • Contact Us
    • Discussions
    Close search

    Activity › Forums › Salesforce® Discussions › How can I update Metadata Components using Salesforce Apex?

    Tagged: HttpRequest, Metadata Components, Salesforce Apex Code, Salesforce Component, Tooling API

    • Salesforce® Discussions

      How can I update Metadata Components using Salesforce Apex?

      Posted by PRANAV on August 16, 2016 at 1:13 PM

      Hi All,

      How can I update Metadata Components using apex ?

      I want to update the attributes of both standard and custom objects by using apex code.

      Thanks

      Avnish Yadav replied 7 years, 2 months ago 3 Members · 2 Replies
      • HttpRequest
      • Metadata Components
      • Salesforce Apex Code
      • Salesforce Component
      • Tooling API
    • 2 Replies
    • Piyush

      Member
      August 17, 2016 at 11:52 AM

      Hello Pranav,

      Here is the sample of code to update metadata through apex code.

      public class ApiCallout {
          public void fetch()
          {
              HttpRequest request = new HttpRequest();
              request = new HttpRequest();
              request.setEndpoint(‘https://ap2.salesforce.com/services/Soap/m/31.0’);
              request.setMethod(‘POST’);
              request.setHeader(‘Content-Type’, ‘text/xml’);
              request.setHeader(‘SOAPAction’, ‘update’);
              String b = ‘<?xml version=”1.0″ encoding=”UTF-8″?>’;
              b += ‘<soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsd=”http://www.w3.org/2001/XMLSchema” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”>’;
              b += ‘<soapenv:Header>’;
              b += ‘<ns1:SessionHeader soapenv:mustUnderstand=”0″ xmlns:ns1=”http://soap.sforce.com/2006/04/metadata”>’;
              b += ‘<ns1:sessionId>’ + UserInfo.getSessionId() + ‘</ns1:sessionId>’;
              b += ‘</ns1:SessionHeader>’;
              b += ‘</soapenv:Header>’;
              b += ‘<soapenv:Body>’;
              b += ‘<update xmlns=”http://soap.sforce.com/2006/04/metadata”>’;
              b += ‘<UpdateMetadata>’;
              b += ‘<currentName>QuoteSettings</currentName>’;
              b += ‘<metadata xsi:type=”ns2:QuoteSettings” xmlns:ns2=”http://soap.sforce.com/2006/04/metadata”>’;
              b += ‘<fullName>QuoteSettings</fullName>’;
              b += ‘<enableQuote>true</enableQuote>’;
              b += ‘</metadata>’;
              b += ‘</UpdateMetadata>’;
              b += ‘</update>’;
              b += ‘</soapenv:Body>’;
              b += ‘</soapenv:Envelope>’;
              request.setBody(b);
              request.setCompressed(false);
              //request.setHeader(‘Authorization’, ‘OAuth ‘ + SESSION_ID);
              String body = (new Http()).send(request).getBody();
              system.debug(‘Hello from body’+body);
          }
      }
    • Avnish Yadav

      Member
      September 30, 2018 at 4:52 AM

      Hello,

      I suggest you to use Tooling API.

      Thanks.

    Log In to reply.

    • Public
    • All Members
    • My Connections
    • Only Me
    • Public
    • All Members
    • My Connections
    • Only Me
    • Public
    • All Members
    • My Connections
    • Only Me

    application solution

    Popular Salesforce Blogs

    5 Productivity Tips by Salesforce System Administrators

    Blog in Salesforce Admin

    Salesforce is a highly transformative platform when used correctly. It has all the tools you need to build and optimize processes. But achieving productivity on…

    AppExchange, Authentication, Autonomy, Bottom Line, Capabilities
    Carol May 22, 2023
    1,356  Views

    Expertise and Support: The Key Benefits of Choosing a Salesforce Partner Company - InfoDrive Solutions

    Blog in Salesforce

    Salesforce is a powerful platform that can help businesses streamline their operations, increase productivity, and improve customer relationships. However, implementing and managing Salesforce can be…

    Appropriate Salesforce Solutions, Best-in-class Solutions, Business Processes, Certification Process, certified professionals
    Infodriven Apr 19, 2023
    1,185  Views

    Why Should I Move My Business to Salesforce

    Blog in Salesforce Consultant

    If you are exploring the realm of the CRM business, you will run into plenty of CRMs, with a considerable lot of them offering the…

    Cloud Based CRM, Features of Salesforce, Programming Model, Salesforce Businesses, Salesforce Consultant
    William Apr 26, 2019
    3,585  Views

    Popular Salesforce Videos

    How to Prepare for Salesforce Platform App Builder (CRT-402) ?

    How to Prepare for Salesforce Platform App Builder (CRT-402) ?

    Video in Salesforce Certifications

    The Salesforce Platform App Builder certification focuses on the different declarative functions available to an admin. Development and code are not included, but it focuses…

    Salesforce Training, Salesforce Certification, Lightning Platform, Salesforce Video, Salesforce Learning
    Jogender Nov 6, 2020
    1,680  Views
    Salesforce Consultant or Salesforce Admin First? | Which is Better?

    Salesforce Consultant or Salesforce Admin First? | Which is Better?

    Video in Salesforce Admin

    In this video, Kaelan Moss - Minute Admin briefs us on whether it's better to be a Salesforce admin or consultant first. Watch the video…

    Salesforce Training, Salesforce Consultant, Salesforce Consulting, Salesforce Admin, Salesforce Video
    Tulika Wadhwani Nov 30, 2022
    1,641  Views
    Salesforce Data Management - Data Loader - Insert, Update, Upsert, Export, Delete

    Salesforce Data Management - Data Loader - Insert, Update, Upsert, Export, Delete

    Video in Data

    Use the Data Loader wizards to add, modify, or delete records. The upsert wizard combines inserting and updating a record. If a record in your…

    Salesforce Training, Salesforce Tutorial, Salesforce Data Management, Salesforce Video, Salesforce Learning
    Prafull Aug 24, 2021
    3,240  Views
    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

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