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 › MetaData Api Call for Users with non-ModifyAllData Permission

    Tagged: Metadata API, ModifyAllData, Salesforce Apex, Salesforce SOQL

    • Salesforce® Discussions

      MetaData Api Call for Users with non-ModifyAllData Permission

      Posted by Akash on March 30, 2016 at 6:15 PM

      We can call metadata api only for the users with ModifyAllData permission so Is there any solution that we can call metadata api for users with non-ModifyAllData permission?

      shariq replied 7 years, 2 months ago 5 Members · 4 Replies
      • Metadata API
      • ModifyAllData
      • Salesforce Apex
      • Salesforce SOQL
    • 4 Replies
    • Ajit

      Member
      April 6, 2016 at 7:06 AM

      http://salesforce.stackexchange.com/questions/68171/running-metadata-api-in-apex-as-a-specific-user

      Have a look on this link, hoping it will help you.

    • Parul

      Member
      September 20, 2018 at 12:52 AM

      Hi,

      The Wsdl2Apex based class will include some additional parts that identify the session.

      There will be an inner class that contains the readMetadata method. It will probably be called something like MetadataPort or MetadataService. This class will include members like:

      public soapSforceCom200604Metadata.SessionHeader_element SessionHeader;
      private String SessionHeader_hns = 'SessionHeader=http://soap.sforce.com/2006/04/metadata';

      It SessionHeader here contains the active SessionId of the user who is making the request. If you replace the value with the SessionId of a user with the "Modify All Data" permission then the call should succeed.

      The trick then becomes how does a non-admin user get a valid admin users session.

      If you had access to the admin users credentials, say via a protected custom setting that is hidden in a managed package, then you could call the login method via the Partner API to get a valid session.

    • shariq

      Member
      September 20, 2018 at 7:36 PM

      Hi,

      I found this on forcetalks blog -

      Running Metadata API in Apex as a specific user

      Calling the metadata API in Apex requires admin permission or at least the “Modify All Data” permission. To run the code as a non-admin user, you need to first login as the system administrator, get a session ID, pass it to the request header, and then make the call.

      To achieve this, we can call SOAP API of Partner or Enterprise WSDL for login as the system administrator, get a session ID and then pass it to the request header, and then make a call.

      Steps for obtaining partner and metadata wsdl and then create a webservice class from it.
      – Generate from Setup in Salesforce (enter API in the Quick Find box, then select API)
      – Download the appropriate WSDL document and save it to a local directory.
      – Generate a Class from WSDL, by clicking “Generate WSDL” Button.

      Example of accessing metadata for read listview with specific user:-

      public static MetadataService.MetadataPort createService() {
      Boolean orgType;
      orgType = [SELECT Id, IsSandbox FROM Organization where Id = : UserInfo.getOrganizationId() LIMIT 1].IsSandbox;
      if(orgType){
      credentials = Credentials__c.getInstance('Sandbox');
      }
      else{
      credentials = Credentials__c.getInstance('Production');
      }

      final String USERNAME = credentials.User_Name__c;

      final String PASSWORD = credentials.Password__c;
      final String SECURITY_TOKEN = credentials.Security_Token__c;
      // Calling Partner class for login with specific user
      PartnerSoapSforceCom.Soap loginConnection = new PartnerSoapSforceCom.Soap();
      PartnerSoapSforceCom.LoginResult config = loginConnection.login(USERNAME,PASSWORD+SECURITY_TOKEN);
      userSessionId = config.sessionId;

      // Calling Metadata Class
      MetadataService.MetadataPort service = new MetadataService.MetadataPort();
      service.SessionHeader = new MetadataService.SessionHeader_element();
      service.SessionHeader.sessionId = userSessionId;
      return service;
      }
      // Calling createService method for reading list view.
      MetadataService.MetadataPort metadataService = createService();
      MetadataService.ListView readListView = (MetadataService.ListView)metadataService.readMetadata('ListView', new String[] { 'product2.'+listViewAPIName.DeveloperName}).getRecords()[0];
      listviewCoumns.addAll(readListView.columns);

      Hope this helps.

    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

    Salesforce career

    Why Do You Have to Learn Salesforce & How Will it Assist You in Your Career Growth in 2021

    Blog in Salesforce Career

    First of all let’s understand, What Salesforce Is? Salesforce is currently the world’s ranked #1 Customer Relationship Management(CRM) solutions provider, according to Forbes it controls…

    Business Development Representative, Business Processes, Career Growth, Certification Possesses, Consultants
    Narendra Sa Aug 23, 2021
    2,663  Views

    How to Eliminate Technical Debt in Salesforce

    Blog in Salesforce

    There are many factors that can affect the quality of the development of your Salesforce org. From increasing complexity to deadlines to lack of technical…

    Apex, Apex Guru, AppExchange, Backlog, Best Practices
    DB Nov 11, 2025
    24  Views
    New and Comprehensive Salesforce Certification Course%0A

    New and Comprehensive Salesforce Certification Course at JanBask Training

    Blog in Salesforce Certifications

    JanBask Training has announced the training and certification course in one of the topmost and market-leading CRM tool Salesforce. It is a well-known fact that…

    Salesforce, Salesforce Certification
    JanBask Nov 3, 2017
    4,422  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.