Draft order creation and activation in a B2B checkout flow
Key Takeaway
Run Cart to Order to create the draft order, then run Activate Order with orderStatus set to the ACTIVATE status code.
In a B2B Commerce checkout flow, a cart becomes an order in two steps: one action creates a draft order, and a second action activates it. The second step depends on the first, and the checkout session controls when each step can run, so a customized flow must keep these steps in sequence.
From cart to order in two steps
Cart to Order runs first and creates a Salesforce standard order in Draft status from the cart. Activate Order must run after it, because Activate Order finds the draft through the orderId stored in CartCheckoutSession.
When Activate Order runs, these things happen:
- The draft order is activated. The order item is also activated and becomes read-only.
- Order summary creation starts, and the order summary is generated asynchronously.
- The cart and the checkout session are archived.
A buyer named Lena is ready to place an order for 40 drill bits. Cart to Order runs first and creates a draft order from her cart. Activate Order runs next and uses the orderId in CartCheckoutSession to find that draft. Lena's order is now active, her order summary is being generated, and her cart is archived.