Skip to content

An APEX implementation of the REST Explorer in the Salesforce Workbench

Notifications You must be signed in to change notification settings

PropicSignifi/RestExplorer.apex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RestExplorer

An APEX implementation of the REST Explorer in the Salesforce Workbench

Features

  • Allows user to call REST API to its own org, in APEX code
  • No OAuth is needed
  • Resolves the session Id problem in lightning context

Examples

Get a description of all available objects in Tooling API:

String result = new RestExplorer('/tooling/sobjects').getResult();

Create a new Tooling API object:

String result = new RestExplorer('/tooling/sobjects/MetadataContainer/')
    .doPost()
    .setBody(new Map<String, Object>{'Name' => 'TestContainer'})
    .getResult();

Run a query on Tooling API:

String query = 'SELECT Id, Name From MetadataContainer WHERE Name = \'MyMeta\'';
String reusult = new RestExplorer('/tooling/query')
    .addParameter('q', query)
    .getResult();

Query all datasets in Wave API and convert the JSON result to a map:

Map<String, Object> result =
    (Map<String, Object>)new RestExplorer('/wave/datasets/').getJsonResult();

Query an Account by its Id:

new RestExplorer('/sobjects/Account/001O000001HbzFwIAJ').getResult();

Update a field in an Account record:

new RestExplorer('/sobjects/Account/001O000001HbzFwIAJ')
    .setBody(new Map<String, Object>{'Website' => 'https://example.com'})
    .doPatch()
    .getResult();

FAQ

What is the SessionIdPage?

The session Id from UserInfo.getSessionId() cannot be used in a lightning context, therefore we have to create a Visualforce Page and get the session Id from there. Reference: https://techevangel.com/2019/06/17/how-to-get-session-id-of-current-user-in-lightning-context/

About

An APEX implementation of the REST Explorer in the Salesforce Workbench

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages