Toggle Side Panel

  • Blogs
  • 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
    • Blogs
    • 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

    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, 11 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);
          }
      }
    • [adinserter block='9']
    • 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

    Popular Salesforce Blogs

    Flows in Salesforce

    Learn About Flows in Salesforce

    Blog in Salesforce Stories

    Salesforce flow, together with process builders and workflows, is a very powerful automation tool. A flow conducts any of the actions specified at the moment…

    Apex Schedule Jobs, Auto Launched Flows, Automated Operations, Automation Tool, Business Procedures
    Sandeep Singh Dec 22, 2021
    4,632  Views

    How to Integrate Salesforce with Magento 2?

    Blog in Salesforce integration

    If you are the owner or a manager of a Magento 2 store and you're seeking for information on how to integrate Salesforce CRM with…

    Connector, Customer Relationships, Error Messages, Integrate Magento with Zapier, Integrate Salesforce
    Anna Jul 8, 2022
    2,501  Views

    Benefits of Salesforce for FinTech: Boosting Efficiency and Scaling Growth

    Blog in Salesforce Implementation

    In recent years, the FinTech industry has boomed and transformed how people manage money, invest, and access financial products. However, with this growth, FinTech organizations…

    Automated Workflows, Benefits of Salesforce, Business Scalability, Cloud Based CRM, Collaboration Tools
    Bacancy Jun 10, 2024
    838  Views

    Popular Salesforce Videos

    Salesforce for Manufacturing: How to Digitize Your Sales Processes

    Salesforce for Manufacturing: How to Digitize Your Sales Processes

    Video in Salesforce Stories, Salesforce Products

    As a manufacturing sales leader, you’re looking for ways to go digital with your sales processes and improve channel performance. In this video, you’ll learn…

    Salesforce Training, Salesforce Video, Salesforce Lerning, Sales Process, Salesforce for Manufacturing
    Rupal Kakkar Mar 9, 2021
    1,968  Views
    Build Lightning Components with Salesforce DX

    Build Lightning Components with Salesforce DX

    Video in Lightning

    Learn how to get started with building Lightning Components, the Salesforce DX way. We'll leverage Base Components, Lightning Data Service, Salesforce CLI, Scratch Orgs, Salesforce…

    Salesforce Lightning, Salesforce Lightning Experience, Salesforce DX, Lightning App Builder, Building Lightning Components in Salesforce
    Portia May 8, 2018
    2,707  Views
    How to get a job in Salesforce industry or ecosystem? (For freshers) | 7 Step Guide

    How to get a job in Salesforce industry or ecosystem? (For freshers) | 7 Step Guide

    Video in Salesforce Development

    The most common question that is asked: How do I get a job? I have learned Salesforce and I know how to create applications on…

    Salesforce Jobs, Salesforce Ecosystem, How to get a job in Salesforce?, Salesforce Industry, Salesforce Guide
    Abhay Jun 20, 2018
    1,895  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

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

    We use cookies to enhance your browsing experience. Please see our privacy policy if you'd like more information on our use of cookies.