0

I am trying to send a SOQL query to salesforce using jsforce. I would like to select all opportunities that are closing within the next year. I firstly tried to use a javascript date but I get an error that it is not of type date.

async function getSFPipelineByMonth() {
    var today = moment(new Date()).add(7, 'days').toDate();
    var query = "SELECT SUM(Amount), CALENDAR_MONTH(CloseDate), CALENDAR_Year(CloseDate) FROM Opportunity WHERE CloseDate < "+ today.toISOString() +" GROUP BY CALENDAR_MONTH(CloseDate), CALENDAR_YEAR(CloseDate)";
    const conn = new jsforce.Connection();
    await conn.login(process.env.SF_USER, process.env.SF_PASS);
    const rs = await conn.query(query);
    return rs;
}

I then tried using SOQL's date literals but I get an error about not being able to use bind variables outside of apex code.

async function getSFPipelineByMonth() {
    var query = "SELECT SUM(Amount), CALENDAR_MONTH(CloseDate), CALENDAR_Year(CloseDate) FROM Opportunity WHERE CloseDate > NEXT_365_DAYS GROUP BY CALENDAR_MONTH(CloseDate), CALENDAR_YEAR(CloseDate)";
    const conn = new jsforce.Connection();
    await conn.login(process.env.SF_USER, process.env.SF_PASS);
    const rs = await conn.query(query);
    return rs;
}

Your Answer

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

Browse other questions tagged or ask your own question.