Follow and complete a Learn MOAR Summer ’22 trailmix for admins or developers by July 31, 2022, 11:59 pm PT to earn a special community badge and enter for a chance to win one of five $200 USD Salesforce Certification vouchers. Restrictions apply. Learn how to participate and review the Official Rules by visiting the Trailhead Quests page.
Introducing Subscription Management
With Subscription Management available Summer ‘22, Salesforce empowers businesses to manage and monetize their business subscriptions across any self-service channel. This new feature enables you to automate the process of billing, invoicing, and collecting payments for subscription products and one-time sales. It also leverages Einstein AI capabilities to evaluate the risk of late payments and maximize revenue.
Subscription Management is powered by some new standard objects on Salesforce core and headless API-first design. The logic for the various processes involved in the subscription is in the APIs. This decouples it from the application layer and allows flexibility for developers to use these APIs with the front-end of their choice, including websites, Slack, and mobile apps.
The API supports common use cases for managing recurring subscription sales, including:
- Calculating prices and price adjustments
- Implementing a “buy now” experience (checkout) across all self-service channels
- Canceling and renewing a subscription
- Handling billing and payments
Get started with the Subscription Management API
To get started, you will need a Salesforce org configured with the following:
- Product data
- Pricing and invoicing information
- A payment gateway
- A tax provider
- Optionally, a connected app for OAuth 2.0 implementation. You’ll need this only if you are using Subscription Management REST API’s to integrate with systems outside of Salesforce core.
You can find more information about the data model for Subscription Management, and how to configure the org to enable this functionality, in Salesforce documentation (available soon).
How to work with the Subscription Management API
The Subscription Management API is a collection of synchronous and asynchronous APIs. These APIs can be accessed securely using tokens obtained via OAuth 2.0 authorization flow using connected apps.
You can chain one or more of these APIs easily to accomplish end-to-end functionality, such as creating a buy now solution (checkout experience) that lets customers select and purchase products using a preconfigured payment method.
The diagram below shows an example of how to chain the REST endpoints of Subscription Management APIs to create a “buy now” solution. See the reference guide to learn more about each of the steps involved.
For Asynchronous APIs, a platform event is published whenever the process is completed. A subscriber can then subscribe to it and listen in one of several ways (see docs).
Invoking the Subscription Management API
You can invoke Subscription Management APIs using one or a combination of tools.
There are different flow invocable actions provided to invoke various Subscription Management APIs. See the docs for an example flow template for a “buy now” solution.
The diagram below shows how to use the Flow pause element to wait for the completion events of asynchronous actions (platform events). In this example, when invoice creation is complete, then an invoice processed event is published.
Apex and LWC
You can call invocable actions via Apex and subscribe to the completion events (platform events) of asynchronous actions via triggers.
You can also build your own LWC components as a front-end to work with the Subscription Management APIs.
ProTip: Leverage the Lightning EMP API base component to subscribe to the completion events (platform events) of an asynchronous action.
When integrating to systems outside of Salesforce core, you can simply invoke REST APIs of Subscription Management using the tools and language of your choice. Easily subscribe to the completion events of asynchronous APIs via the cometD client available in various popular open source languages.
The example below shows an HTTP request body that creates an order for an evergreen subscription.
We have a couple of assumptions: 1) the subscription costs $10/month and starts January 1, 2021, with an estimated sales tax of 7.25%, and 2) the following information is configured for the records that are referenced in the request.
- The account has a billing address and shipping address
- The price book entry is configured for an evergreen product
- The default billing treatment and tax treatment is configured for the product
- The default payment term is configured
- Salesforce Subscription Management Guide — this helpful guide shows some of the solutions you can build using Subscription Management APIs.
- Subscription Management API reference — this is a one stop shop for everything you want to read about Subscription Management APIs.
Learn MOAR this week
Product Managers and the Developer Relations team are back to share the latest features and functionality in Summer ‘22. To help you develop faster, new content from Developer Relations will cover their favorite new features. Also, be sure to check out Release Readiness Live on Friday, May 20, 2022 at 9:00 a.m. PST. Lastly, keep an eye on the Salesforce Developers blog every day this week for more posts on Summer ’22!
To learn even more, check out the Summer ’22 trailmix.
About the author
Mohith Shrivastava works as a Lead Developer Advocate at Salesforce. He is currently focusing on APIs & Integrations and Developer Tooling. You can follow him via Twitter @msrivastav13.