0
votes

Customer wants a way to expose sandbox metadata in their system.

So basically, they manage other salesforce orgs. They want the ability create a connection object to link their prod org to another sandbox.

Then linking that connection to another object which has a picklist.

The picklist will be say "Apex Class". when that is chosen, the connection should list all Apex Classes in the sandbox.

How can this be achieved?

3

3 Answers

1
votes

You will need to use the Metada API from salesforce, there are some libraries that will help you I use Jsforce. So basically you can create a connection to the sandbox on the production organization on the visual force page using plain javasccript and you could list any object from the sandbox.

1
votes

Andrew Fawcett has a written wonderful apex wrapper class for salesforce metadata api.

Please refer: https://github.com/financialforcedev/apex-mdapi

There is a "Deploy to Salesforce" button which you can click and it will deploy this whole codebase in your developer org easily.

Then, you can reference his classes from your apex code/VF code. Try it out. You will like it a lot :)

0
votes

The simplest way to do this is using the Tooling API. You can test it in the developer workbench https://workbench.developerforce.com/restExplorer.php.

For example, to get a list of all Apex Classes you would make a GET request to this path:

/services/data/v37.0/tooling/query?q=SELECT+Name+FROM+ApexClass

Or to get a list of Workflow Rules:

/services/data/v37.0/tooling/query?q=SELECT+Name+FROM+WorkflowRule

In Apex, you can just make an http request to those endpoints. The result would be in JSON format. You can deserialize it using the built in Apex JSON library.