Salesforce Functions (now retired/in transition; Heroku Apps remain the path) let you offload compute-heavy work to Heroku containers running outside Salesforce, callable from Apex.
Why: governor limits cap Apex compute (10s CPU sync, 60s async, 6 MB heap). Heavy work (large image processing, ML inference, complex algorithms, data transformations) doesn't fit. Functions/Heroku run server-side in Node/Python/Java/Go without those caps.
Pattern:
- Build a Function/Heroku app — accept HTTP POST, do heavy work, return JSON.
- Deploy via Heroku CLI or Salesforce Functions tooling.
- Connect Salesforce to Heroku via Salesforce Connect or Heroku Connect (data sync).
- Apex calls the function via HTTP callout (Named Credential).
apex HttpRequest req = new HttpRequest(); req.setEndpoint('callout:Heroku_App/generate-pdf'); req.setMethod('POST'); req.setBody(JSON.serialize(payload)); HttpResponse res = new Http().send(req);
When to use: image manipulation, PDF generation at scale, ML model inference, complex calculations beyond governor limits, integrations needing libraries Apex doesn't have.
Salesforce's specific "Functions" product had a complicated history; modern guidance is "use Heroku directly" or evaluate Salesforce's evolving compute offerings.
