Code Monkey home page Code Monkey logo

remotesitesettingcreator's Introduction

Remote Site Setting Creator

Create a Remote Site Setting for the Salesforce API automatically if absent using the Metadata API.

Problem

At times, we might end up in a situation wherein we need to make calls to the Salesforce API itself such as it's REST API or so. One such example could be accessing the ListView API. In such instances, one would have to add the Endpoint URL to the Salesforce API as a Remote Site Setting in order to make calls to this endpoint from within Apex. That being said, it get's even more complicated if we have to ship this as an AppExchange App since endpoints to the Salesforce Org itself is going to vary from customer to customer.

Solution(s)

So we have two solutions to this problem:

  • Using the Metadata API from Apex. The idea is to use the Metadata API from Apex to create the Remote Site Setting. In order to do that, you will have to use the popular - apex_mdapi. You could then possibly invoke the same from the PostInstallClass.

  • Using the Metadata API from JS. Instead of using Apex, we would spawn the Metadata API from JavaScript. You will create a Visualforce Component that lies on that VF Page that might want to make calls to the Salesforce API. The calls to Salesforce Metadata API from JavaScript will be done via the excellent jsforce library.

This repo explains how we can achieve this using the second method - Using the Metadata API from JS.

Usage

In order to use this VF Component, all you have to do is to just include the Component on the VF page:

<apex:page>
    <c:RemoteSiteSettingCreator />
</apex:page>

The Component generates a JS Object called RemoteSiteSettingCreator on the Window object. It exposes a flag - RemoteSiteSettingCreator.constants.remoteSiteSettingCreated that can be later utilized in the application life cycle to determine if the setting was created or not.

Also, the Component has an optional callback attribute that can accept JS code as a string literal and the same will be evaluated after the setting has been created successfully.

<apex:page>
    <c:RemoteSiteSettingCreator callback="alert( 'Done!' );" />
</apex:page>

Note

The component already has code that will automatically perform a check if the endpoint has been added previously or not. If there exists one then it will not add a duplicate entry in the Remote Site Settings.

Deployment

Use the below button to deploy this to your SF Org in a single click!
Deploy to Salesforce

Licensing

Completely free! Use it at your own will.

remotesitesettingcreator's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.