Skip to content
RIO Education
  • Home
  • RIO Education
  • Knowledge Base
  • Contact Us
  • News
RIO Education
  • Home
  • RIO Education
  • Knowledge Base
  • Contact Us
  • News

Salesforce: Accessing Metadata API via Javascript

By Lean | May 21, 2018

Recently, Salesforce has enabled the metadata API in Apex. However, this is only limited to page layout and custom metadata types at the moment. This is a good news for a developer like me as I need it to achieve this “natively” within Salesforce.

So what are the options that are available for the time being if we want to access the other metadata? One good way that I found in the community is JSforce. This free tool helps you to access the metadata API via javascript (and command line) with just a few easy steps.

Are you worrying about authentication? Don’t worry this tool supports oAuth authentication which secure your username/password from others.

Here is a quick example of using the tool to retrieve metadata for Account and Contact in a Visualforce Page. Note that as I’m using Visualforce Page, I can utilize the $Api.Session_Id to get my current session id within Salesforce instead 🙂

 

<apex:page docType="html-5.0" showHeader="false">
    <apex:includeScript value="https://cdnjs.cloudflare.com/ajax/libs/jsforce/1.7.0/jsforce.min.js" />

    <script>
        var conn = new jsforce.Connection({ accessToken: '{!$Api.Session_Id}' });
        var fullNames = [ 'Account', 'Contact' ];

        conn.metadata.read('CustomObject', fullNames, function(err, res) {
            if (err) {
                return console.error(err);
            }

            for (var i=0; i < res.length; i++) {
                var metadata = res[i];
                console.log("Full Name: " + metadata.fullName);
            }
        });
    </script>
 </apex:page>
Posted in Salesforce Corner and tagged metadata api, Salesforce, salesforce apex, Salesforce Developer, SFDC, SFDC Australia

Search

Categories


Tags

boomi boomi integration Caloundra Film Festival case study dell boomi Higher Ed higher education integration Italian Film Festival JIRA Lightning MYOB MYOB integration Netsuite netsuite integration rightnow rio RIO Education RIO Education for Salesforce saasu saasu integration Salesforce salesforce apex salesforce apex class Salesforce Apex Trigger salesforce appexchange Salesforce CRM Salesforce Developer salesforce higher education salesforce integration salesforce student information system SFDC SFDC Australia SIS sms Sponsors Student Information System student management system talend Talend Integration Visualforce wdci team wdci_wedid wedid-integration wedid-salesforce

Salesforce best blog

© 2022 RIO Education | Powered by Beaver Builder