ADR 0010: Org automation, lead convert and merge¶
- Status: accepted, 2026-11-09
- Source:
big-bang.md§2, decisions D14, D26 (details in §9.7, §9.8)
Context¶
Salesforce has no REST resource for lead convert or merge, anywhere on the platform. Org logic lives in invocable actions, Flows and Apex.
Decision¶
- Lead convert and merge will be normal methods with SOAP hidden inside, using OAuth tokens, never SOAP login (D14).
- Org automation is reached through generic calls to invocable actions (standard, Flow, Apex) and
Apex REST.
esf generate actionswill produce typed stubs. Anonymous Apex lives under Tooling and runs only when called explicitly. Triggers can't be called directly (D26).
Implementation (0.2)¶
sf.leads.convert(),sf.leads.convert_many()(100 per call) andsf.merge()(Lead, Contact, Account; one or two duplicates) post Partner SOAP envelopes to/services/Soap/u/{version}. The access token goes inSessionHeader.sessionId, built per attempt so a refreshed token gets a new body. NoAuthorizationheader goes to the SOAP endpoint.- Envelope building and parsing are pure functions in
core/soap.py. The parser is stdlibexpatand refuses any DTD or entity declaration. Faults map byexceptionCodeto the §8 classes, elseSoapFault. - Sources: convertLead(), LeadConvertResult, merge(), Error handling. The wire details still need a sandbox check (V11, V35).
Consequences¶
- None of this is in 0.1. Actions, Apex REST helpers and convert/merge are planned for 0.2, and
Tooling for 0.3.
esf generateexits with "not available until 0.2".
Implementation notes (0.2)¶
sf.actions.standard/flow/apex(name, inputs)take one dict or a list. One input returns the output values, or raises the typed error of its first error entry. A list returns aBatchResult[ActionResult]. A400whose body is the per-invocation result list is not an HTTP error for these calls; the area maps eachisSuccess=falseentry itself.sf.apex.*errors becomeApexErrorwith the decoded body. Auth errors, limit errors, gateway errors with an empty body and non-JSON pages keep their own classes, so refresh and retries still work.sf.request()on an Apex REST path keeps the status-based mapping.esf.Action[R]stubs are dataclasses or Pydantic models with__action__ = (kind, name);sf.run(stub)sends the fields under their API names and buildsRfrom the outputs.esf generate actions --org NAMEreads the login fromESF_<NAME>_*variables (the CLI reads the login only from the environment, §9.18), not fromsfCLI aliases (rejected under D29).- Sources: Invoking Actions, Flow Actions, Apex Actions, Apex REST. Open points are V31–V34 in the spec's verification backlog.