• Michelle Chapman Thurber
  • NEWBIE
  • 5 Points
  • Member since 2011
  • Lead Technical Writer
  • salesforce.com


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
I am looking at the Tooling API for an example on how to create a class. I took a a look at this example and I suspect this documentation is outdated.

https://developer.salesforce.com/docs/atlas.en-us.198.0.api_tooling.meta/api_tooling/intro_soap_overview.htm

If you read the page it says "These Examples use java". This is incorrect. Console.WriteLine is not present in Java. It is a feature of C#.
When you attempt to compile this code, there are further errors.
 
String classBody = "public class Messages {\n"
   + "public string SayHello() {\n"
   + " return 'Hello';\n" + "}\n"
   + "}";

// create an ApexClass object and set the body 
ApexClass apexClass = new ApexClass();
apexClass.Body = classBody;
ApexClass[] classes = { apexClass };

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

Is there a specific example on how to use tooling API?