I'm wondering if it's possible to create programmatically a Salesforce organization (DEV or Sandbox).

2 Answers 2


You can create a SandboxInfo to create a new sandbox. I do not think this works directly in Apex, but you should be able to make an API call against your org to initiate a creation or refresh.

  • Thank you so much. What about a dev edition org?
    – Azerty SF
    Dec 28, 2018 at 15:16
  • @AzertySF No, there's no API for creating "real" developer orgs. You can create a Scratch Org that's a Developer Edition using SFDX, but they expire in a maximum of 30 days. If you're trying to do some sort of continuous integration, SFDX is how you'd want to do this.
    – sfdcfox
    Dec 28, 2018 at 15:18

Yes you can do that, You can use Salesforce SFDX command line client to create Scratch (Developer orgs),

And as its a command line you can program it as per your need.

You can go through the trailhead which will let you know the steps to do it.


If you are in hurry, you can just dig into the developer guide https://resources.docs.salesforce.com/210/latest/en-us/sfdc/pdf/sfdx_dev.pdf

  • Thank you. What if we want to create it using Apex?
    – Azerty SF
    Dec 24, 2018 at 13:54
  • create a new org via apex is not supported yet, probably in future. :) Dec 24, 2018 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.