2

I'm trying to use the Tooling API in order to create new sandboxes via a Console application in .NET, with C#.

So far I've been able to authenticate with the partner wsdl and perform overall queries, etc. The problem is I can't find barely any information on the Tooling API except the offical SOAP docs and even less code samples which try to do anything.

As far as I've understood, according to the official docs I need to:

  1. Create a SandboxInfo record.
  2. To find the status of a sandbox after it is enqueued, query SandboxProcess for a given SandboxInfoId field to find the latest SandboxProcess record. The value of Completed in Status indicates that the creation process is finished.

But how can I do this in C#? If you could guide me through the flow and point me to some classes, I'm sure I can find my way :)

Thanks!

2

It sounds like you are using the SOAP API version of the Tooling API rather than the REST version.

You will need to generate the Tooling API WSDL from a production org. Only production orgs have access to the SandboxInfo sObjects.

After that you will just want to directly call the create() method passing it a SandboxInfo. This is more or less laid out in an example.

// create an ApexClass object and set the body 
SandboxInfo sandboxToCreate = new SandboxInfo();
// Must be 10 or fewer characters
sandboxToCreate.SandboxName = "UniqueSand"; 
// ID of a SandboxInfo that serves as the source org for a cloned sandbox.
sandboxToCreate.SourceId = "0GQ000000000001";
sandboxToCreate.Description = "New Sandbox Description";
sandboxToCreate.HistoryDays = 0;
// Might be an enum
sandboxToCreate.LicenseType = "DEVELOPER"; 
SandboxInfo[] sandboxesToCreate = { sandboxToCreate };

// call create() to add the class
SaveResult[] saveResults = sforce.create(sandboxesToCreate);
for (int i = 0; i < saveResults.Length; i++)
   {
   if (saveResults[i].success)
      {
        Console.WriteLine("Successfully created SandboxInfo: " +
         saveResults[i].id);
      }
   else
      {
         Console.WriteLine("Error: could not create SandboxInfo ");
         Console.WriteLine("   The error reported was: " +
         saveResults[i].errors[0].message + "\n");
      }
   }

After this the Sandbox creation will be enqueued. You will need to poll SandboxProcess to monitor the status.

You should be able to access it against the REST API against a production org as well. There is (more or less) parity between the SOAP and REST versions of the API.

  • Do you mean that I can create Sandboxes via the REST version too? I did see that it supported sobjects, but I never thought the SandboxInfo and SandboxProcess would be considered sobjects. – Javier García Manzano Apr 7 '18 at 10:22
  • Anyway, I did try to type SandboxInfo, but Visual Studio would not recognize such a class. Is it because I'm missing some kind of config? What I was setup the Service Reference for both the Tooling wsdl and the Partner wsdl. Just as a heads up, in the example they do it with ApexClass and Visual studio does recognize that class, but not the SandboxInfo. – Javier García Manzano Apr 7 '18 at 10:23
  • You will likely need to generate the Tooling API WSDL from a production org. Only production orgs have access to the SandboxInfo sObjects. You should be able to access it against the REST API against a production org as well. There is (more or less) parity between the SOAP and REST versions of the API. – Daniel Ballinger Apr 7 '18 at 10:58
  • Ok, that makes total sense then. I was using a developer org. How stupid rofl. All understood now! If you don't mind, could you include all this info in the answer? Thanks for the hassle, Daniel! – Javier García Manzano Apr 7 '18 at 11:01

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.