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, 3 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

    Digital-First Fundraising Strategies | The Salesforce Guide

    Blog in Salesforce

    We are going through unrivaled and uncertain times globally. There is a health crisis, economic breakdown, leadership turmoil, matters of social justice, and environmental challenges…

    AppExchange, Benefits of Technology, Campaigns, Communications, COVID-19
    Apphienz May 21, 2021
    1,962  Views
    Salesforce Data Exporting

    Salesforce Data Exporting Options

    Blog in Data, Salesforce

    Data Loader Export CSV files manually or should configure the tool to automatically run at scheduled times to send out CSV to a destination location…

    Create Export Files, CSV, CSV Files, Custom Script, Custom Scripting
    Sharath Chandra Feb 8, 2022
    5,316  Views
    Salesforce Change Management

    The What, Why, and How of Salesforce Change Management

    Blog in Salesforce, Salesforce Products

    If you are introducing new features or processes to a Salesforce instance, then you might make or break the system. In the contemporary business environment,…

    Application, Assessment Template, Business Eenvironment, Business Goals, Business Objectives
    Cloudideas Jun 15, 2021
    1,777  Views

    Popular Salesforce Videos

    After Triggers | Trigger in Salesforce - Part 2

    After Triggers | Trigger in Salesforce - Part 2

    Video in Others, Salesforce Apex

    In this video, we are going to look into - After Trigger with Example, Our Scenario is - For After Insert Whenever my account record…

    Salesforce Training, Apex, Salesforce Trigger, Salesforce Video, Salesforce Learning
    kanika Mar 22, 2021
    3,870  Views
    Salesforce Winter '21 Highlights

    Salesforce Winter '21 Highlights

    Video in Salesforce Stories

    Even in these unprecedented times when the world is struggling with a major pandemic that has brought everything to a standstill, Salesforce has strived hard…

    salesforce, User Experience, Salesforce Video, Salesforce Learning, Salesforce Release
    Rupal Kakkar Oct 8, 2020
    1,853  Views
    Salesforce For Non Programmers | Salesforce For Non Technicals

    Salesforce For Non Programmers | Salesforce For Non Technicals

    Video in Salesforce Training

    You can learn Salesforce without any programming language. You can plan Salesforce Administrator Certification which requires no coding skills. Watch this video to learn how.

    Salesforce Training, Salesforce Tutorial, Salesforce Certification, salesforce, Salesforce Video
    Jogender Jan 21, 2022
    4,312  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®.

    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.