1

I want to orchestrate logic distributed in Salesforce and in an External system in a scalable way using Platform events.

Functional requirements:

  1. User in Salesforce triggers logic (Apex, Flow,...)
  2. Logic makes a callout to external system
  3. External system does its magic (can take hours)
  4. External system notifies Salesforce using Platform Event that job has succeeded
  5. Salesforce fetched result data from External System
  6. Salesforce resumes logic stopped in 2.

Nonfunctional requirements:

  1. Stopping and resuming logic should be built in a native and generic way. Not thousands of moving parts (triggers, Continuations, Apex invocations)
  2. Send Platform event from External system after long-running job without storing credentials in Backend (Connected App?)

What are my options? What are each option's pros and cons? Are there simple sample apps to start from?

6
  • 2
    Sounds like this could overlap with BPEL4People aka "WS-HumanTask Specification" type processing. I don't think Salesforce has this sort of capability OOTB and it comes down to writing some custom SOA services to support the concept of task hand-off and return. Without this support in the platform, or at least an external task work list server with standardized API, this may not be a goer for you. Note that I've not even thought about BPEL in connection with Salesforce at this point...
    – Phil W
    Dec 15, 2020 at 14:18
  • I am not talking about Human tasks.I just want Apex code resume where it left of after a Platform Event is received Dec 15, 2020 at 14:37
  • 2
    A human task doesn't actually have to be performed by a human; the important point is that these tasks are asynchronous and may take hours or days to complete. Anyway, if this concept isn't applicable, ignore me :D
    – Phil W
    Dec 15, 2020 at 15:04
  • 1
    Does this answer your question? Breaking a flow into 2 different transactions
    – identigral
    Dec 15, 2020 at 17:26
  • @identigral not a complete all encompassing answer but definitely a part. I also (and you might be the perfect expert) need to understand how the backend authenticates and sends an event. Dec 15, 2020 at 17:37

1 Answer 1

1

There's no single feature that is responsive to all of these functional needs. You'll need to do some work, possibly quite a bit of work, both to build this overall process orchestration and to make it resilient to failures and limits issues, which is probably harder.

User in Salesforce triggers logic (Apex, Flow,...)
Logic makes a callout to external system
External system does its magic (can take hours)
External system notifies Salesforce using Platform Event that job has succeeded Salesforce fetched result data from External System Salesforce resumes logic stopped in 2.

You can do this with Flow, for sure. However, you'll be subject to the limits on paused and resuming Flow interviews (1,000 resumes per hour) and the unusual limits regime that comes from the fact that Flows are resumed in batches that share transaction limits, which may or may not be compatible with your application's scale needs. Additionally, Flow resumes are not 100% real time, which also may or may not be compatible with your expectations, and you might not be able to get the kind of instrumentation or error monitoring you need.

You could also do it with Apex, through a combination of, e.g.,

  • A trigger to start the process.
  • A Queueable to run the callout.
  • A custom object to persist process state during external system processing
  • A Platform Event trigger to resume the process by consuming the custom object.
  • Possibly additional components depending on the scope and complexity of the automation.
  • Some kind of solution to monitor errors, dangling transactions, etc., and surface them for admin resolution.

Send Platform event from External system after long-running job without storing credentials in Backend (Connected App?)

You can't do that unless you're willing to use webhook authentication on a REST API endpoint exposed on a public Site, which I would strongly recommend against. I would use JWT authentication to avoid storing credentials.

You must log in to answer this question.

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