I'm trying to run Apex tests using JSForce and it returns me the error:

Catch error: TypeError: classnames.join is not a function

I'm making a post request

.get((req, res) => {
.post(async (req, res) => {
    const sfConnection = await initSFConnection();
    const message = runApexTest(sfConnection)

and the runApexTest :

async function runApexTest(sfConnection) {
     var testsArray = [{
        className: "SolutionTest",
        testMethods: ["findSumTest"]
    var body = {"tests": testsArray};

    logger(`body : ${JSON.stringify(body)}`);

 var message;
try {
    const result = await sfConnection.tooling.runTestsSynchronous(JSON.stringify(body));
    logger(`TEST result : ${result.body}`);
} catch (error) {
    logger(`Catch error: ${error}`);
} finally {
    return message;


The body log looks like this:

body : {"tests":[{"className":"SolutionTest","testMethods":["findSumTest"]}]} 

I don't know what I'm doing wrong.The errors seems like a JavaScript error. I ran the same body with Postman and it works. The org connection is established I can execute anonymous apex but just this end point doesn't work. Any hints are appreciated.

  • I also tried passing just the body body without stringifying it. Still the same issue persist. Feb 8 at 19:34

1 Answer 1


Do not JSON.stringify. The method is expecting two parameters, an array of class names, and a callback method.

var body = ['Class1','Class2','Class3'];

Also, jsForce doesn't use promises. You need to pass a callback function as the second parameter.

  • I tried passing just the body without stringifying it. Initially I setup the body according to the salesforce documentation I rewrote the code to look like this. var body = ['SolutionTest']; sfConnection.tooling.runTestsSynchronous(body, (req, res) => { logger(TEST result : ${res}); }); returning null now. Why are the documentations contradicting? Feb 8 at 20:36
  • @AslahPHussain jsForce wraps the classnames into the proper format. I'm not familiar with jsForce; try logging all the parameters and see what you get: (...res) => { console.log(res) }
    – sfdcfox
    Feb 8 at 21:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .