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 8 years 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

    Objects In Salesforce

    Understanding Objects In Salesforce - All You Need To Know

    Blog in Salesforce

    It Takes 2 Weeks To Understand Objects in .Net and Java, But In Salesforce It Takes 2 min. Here Is How! In Salesforce, objects are…

    Apprentice to Salesforce, Build a Custom Object, Credit Card, Custom Objects, Customer Details
    Gourav Deep Das Sep 10, 2020
    6,491  Views
    SSO Implementation of two Salesforce Orgs in Lightning and Classic view

    SSO Implementation between two Salesforce Orgs in Lightning and Classic view

    Blog in Salesforce Implementation, Salesforce Security

    We can implement SSO for both Lighting and Classic view with the help of SAML. There is no difference between security protocol for both. Requirement:…

    Classic View, Lightning View, Salesforce Classic, Salesforce Implementation, Salesforce Lightning
    Neha Mar 23, 2018
    9,952  Views
    Record Locking

    All About Record Locking in Salesforce

    Blog in Others, Salesforce

    In this blog entry, I'd examine the various approaches to secure a Salesforce record UI. By lock, I mean, the client shouldn't have the option…

    Approval Process, Arrangement Closing, Bolt a Record, Business, Business Measure
    Aditya Jan 6, 2021
    10,973  Views

    Popular Salesforce Videos

    Creating Datasets - Tableau CRM | Salesforce Tutorial

    Creating Datasets - Tableau CRM | Salesforce Tutorial

    Video in Data, Salesforce Training

    Recipes provide an easy way to update, combine and transform your sources into the datasets you'll use to drive your dashboards. You'll see how to…

    Salesforce Training, Salesforce Tutorial, salesforce, CRM, Salesforce Video
    Vivek Jan 4, 2022
    2,787  Views
    Getting Started With Business Analysis | Scrum Development Model | Salesforce Tutorial

    Getting Started With Business Analysis | Scrum Development Model | Salesforce Tutorial

    Video in Others, Salesforce Training, Salesforce Development

    Learn all about AGILE software development and the scrum development model. 1. Introduction To AGILE Get a brief definition of AGILE and its different modules.…

    Salesforce Training, Salesforce Tutorial, Agile, Salesforce Video, Business Analysis
    Algoworks Feb 8, 2021
    2,573  Views
    Implement Time Based Workflow | Salesforce Tutorial

    Implement Time Based Workflow | Salesforce Tutorial

    Video in Others, Salesforce Training

    If you ask any Salesforce Person, which kind of workflow is difficult to understand and implement, the obvious answer will be the Time Based on…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Video, Salesforce Learning
    Sam J Oct 12, 2020
    1,973  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.