function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Abhijit Shrikhande 10Abhijit Shrikhande 10 

Tooling API - Outdated Documentation?

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?
 
pconpcon
All of the tooling API work I have done has been either directly against it as a REST endpoint or via jsforce [1].  I would recommend that you point out this descrepancy to the salesforcedocs team on twitter [2].  They are pretty responsive there.

[1] https://jsforce.github.io/document/#tooling-api
[2] https://twitter.com/salesforcedocs
James LoghryJames Loghry
It wouldn't be the first time there's an error in the documentation.  If you're on twitter, I suggest you bring it up with @salesforcedocs.  There's not a whole lot of relevant examples out there on how to interact with the Tooling API.  You can take a look at the following github repo, which is geared towards Apex (not Java), and see if that potentially helps.  Keep in mind though, it hasn't been worked on in quite some time and is itself outdated: https://github.com/afawcett/apex-toolingapi

Another resource which has helped quite a bit in the past is poking around with the REST explorer on workbench (workbench.developerforce.com).  From there, you can explore the various Tooling API operations and how to request and handle the responses.

Other than those few things, there's really not much out there when it comes to the Tooling API.
Abhijit Shrikhande 10Abhijit Shrikhande 10
I have been playing along with the Tooling API using REST, but then I noticed that the REST based approach has more limits than the SOAP based approach. I wish Salesforce.com would improve its documentation.
Abhijit Shrikhande 10Abhijit Shrikhande 10
@pcon - Are you able to set TraceFlags via the Tooling API using JsForce?
pconpcon
I have not tried setting Trace Flags via jsForce
Michelle Chapman ThurberMichelle Chapman Thurber
Hi everyone! I'm with the @SalesforceDocs team. Thanks for reporting this! I'll pass it on to our API writers. 
Diego NietoDiego Nieto
Hi everyone, i'm using jsforce to create Leads from an external application, I have to connect with salesforce. I0m using nodejs and working with jsforce to do that. The problem is that everytime that I try to send data. I always recieve this error:

{ JSON_PARSER_ERROR: Cannot deserialize instance of string from START_ARRAY value [line:1, column:21]
    at HttpApi.getError (D:\Zagalabs\Cipress Hill\SFIntegration\node_modules\jsforce\lib\http-api.js:250:13)
    at D:\SFIntegration\node_modules\jsforce\lib\http-api.js:95:22
    at tryCallOne (D:\SFIntegration\node_modules\promise\lib\core.js:37:12)
    at D:\SFIntegration\node_modules\promise\lib\core.js:123:15
    at flush (D:\SFIntegration\node_modules\asap\raw.js:50:29)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9) name: 'JSON_PARSER_ERROR', errorCode: 'JSON_PARSER_ERROR' }

the problem is that i'm using the last version and in the documentation there are not information about this error. My code is this one:

conn.sobject('Lead').create({
                            FirstName : excelData[j]['First Name'],
                            LastName : ['Last Name'],
                            Company : company,
                            Email : excelData[j].Email,
                            Phone : excelData[j]['Phone 1'],
                            Address : parseString(excelData[j]['Service address']),
                            BillingCity__c : excelData[j]['City'],
                            BillingPostalCode__c : excelData[j]['ZIP']},function(err,ret){
                                if (err) { return console.error(err); }
                                console.log(ret.id);
                        });

What I'm doing wrong?

Thanks
pconpcon
This sounds like you have a problem in your object definition.  I would change your code to be this 
 
var data = {
    FirstName : excelData[j]['First Name'],
    LastName : ['Last Name'],
    Company : company,
    Email : excelData[j].Email,
    Phone : excelData[j]['Phone 1'],
    Address : parseString(excelData[j]['Service address']),
    BillingCity__c : excelData[j]['City'],
    BillingPostalCode__c : excelData[j]['ZIP']
};

console.log(JSON.stringify(data));

conn.sobject('Lead').create(data ,function(err,ret) {
    if (err) {
        return console.error(err);
    }

    console.log(ret.id);
});

My guess is that you need "excelData[j]['Last Name'] on line 3 (of the code above) to fix this issue.
Diego NietoDiego Nieto
cmpletly right!! that was the problem!! but now i have another problem here, this lead creation is in a for, the error now is
Error: Exceeded max limit of concurrent call
    at Connection.insert.Connection.create (D:\Zagalabs\Cipress Hill\SFIntegration\node_modules\jsforce\lib\connection.js:619:27)
    at SObject.insert.SObject.create (D:\Zagalabs\Cipress Hill\SFIntegration\node_modules\jsforce\lib\sobject.js:62:21)
    at compareData (D:\Zagalabs\Cipress Hill\SFIntegration\fileManager.js:49:42)
    at D:\Zagalabs\Cipress Hill\SFIntegration\fileManager.js:16:13
    at promiseCallback (D:\Zagalabs\Cipress Hill\SFIntegration\node_modules\jsforce\lib\query.js:334:15)
    at .<anonymous> (D:\Zagalabs\Cipress Hill\SFIntegration\node_modules\jsforce\lib\query.js:347:5)
    at g (events.js:291:16)
    at emitTwo (events.js:106:13)
    at emit (events.js:191:7)
    at D:\Zagalabs\Cipress Hill\SFIntegration\node_modules\jsforce\lib\query.js:431:12
that means that i can't do recurrent insert to the API? i'm only sending five or six records,

thanks a lot!
 
pconpcon
Are you doing the create as a single call?
 
conn.sobject('Lead').create([
    { //Data for object 1 },
    { //Data for object 2 },
    { //... }
], function (error, results) {
    if (error) {
        return console.error(error);
    }

    for (var i = 0; i < results.length; i++) {
        if (results[i].success) {
            console.log(results[i].id);
        }
    }
});

 
Diego NietoDiego Nieto
Finally found the problem, some data in the final object was text like '[qweras]#$', the characters were there with a problem in a previous process. For the rest all the process and optios here were correct. Thanks a lot for your help