2

I have an auto launch flow that I'd like to act as an API endpoint. The flow receives a few variables and creates tasks and cases.

I've used jsforce to call an apex rest API like it's explained here.

Here's my code example of using jsforce to call an apex endpoint:

const salesforce = config.getProperty('NewSalesforceRest');
const conn = new sf.Connection({ loginUrl: salesforce.host });

try {
  await conn.login(salesforce.userName, salesforce.Password + salesforce.Token);
} catch (error) {
  return res.status(500).send(errorResponse.ServerError(`Salesforce Apex login failure: ${error}`));
}

const apexPostResult = await conn.apex.post('/contact_us', req.body);

Is it possible to use jsforce to launch the flow? and if yes, could you please direct me to documentation or example on how to do it? or just post a sample as an answer?

3
  • a down vote without any explanation doesn't help. please let me know what's wrong with my question and allow me to make it a better question. what you've done doesn't help at all.
    – Bahman.A
    Dec 2, 2022 at 21:51
  • 1
    @Bhaman Not that I downvoted this but better off if you show some code of what you tried and where you stuck. Dec 2, 2022 at 23:49
  • Thanks, @MohithShrivastava I've added more details and code examples.
    – Bahman.A
    Dec 5, 2022 at 22:31

2 Answers 2

3

You can send an arbitrary request to Salesforce, and it so happens that you can call a Flow directly.

First, build the request as:

var _request = {
  url: '/services/data/v54.0/actions/custom/flow/FlowName',
  method: 'post',
  body: JSON.stringify(
    {
      inputs: [
        param1: value1,
        param2: value2,
      ]
    }
  ),
  headers : {
          "Content-Type" : "application/json"
      }
};

Which you then send after logging in and resetting the login url:

conn.request(_request, function(err, resp) {
     console.log(resp);
});

Be sure to visit the first link and provide an upvote there, too. I'm just putting it all together for you.

2
1

Another option: use jsforce to execute anonymous Apex which calls your flow, like this:

const apexCode = `Flow.Interview flow = new Flow.Interview.MyFlowApiName(
    new Map<String, Object>{
        'stringParam' => '${myString}',
        'numberParam' => ${myNumber}
    }
);`
await conn.tooling.executeAnonymous(apexCode);

See this other thread for more about invoking an auto-launched Flow from Apex.

You must log in to answer this question.

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