Custom Actions to Activate Contracts

You can implement customizations to activate contracts automatically. You can do this programmatically via the API, or you can do it without writing code by invoking either of the following Apex actions from a Salesforce flow:

Category

Apex Action Apex Class Purpose
Billing Contract Activate Billing Contracts ContractsServiceActionActivate

Takes a billing contract ID and activates it. An input option determines whether billing schedules are generated for the active contract.

Billing Contract Activate Billing Contracts Asynchronously ContractsServiceActionActivateAsync

Takes a collection of billing contract IDs and activates them in the same way that contracts are activated from the Billing Contracts list view. For details, see Activating Contracts.

Billing schedules are generated for the active contracts according to the Billing Schedule Number of Months field in the Billing Central Settings custom setting.

Inputs and Outputs for the Activate Billing Contracts Apex Action

Input Parameters

The Activate Billing Contracts Apex action has the following input parameters for each billing contract passed to it.

Parameter

Required or Optional

Description

Billing Contract ID to be activated Required ID of the contract to be activated.
Generate Billing Schedules using a batch job that runs asynchronously. Required

Boolean to specify whether billing schedules should be generated for the activated contract. When true, billing schedules are generated via a batch job.

Warning:

Depending on the context in which you invoke this Apex action, platform restrictions might prevent a batch job from being launched in the same execution context. For example, if you have a batch job to approve contracts and trigger this flow, that batch job cannot start another batch job so it will report failures if this boolean is true. In this situation, leave the boolean set to false and allow billing schedules to be generated by the GenerateBillingSchedulesSchedulable Apex job. See Setting up a Job to Generate Billing Schedules.

Output Values to Store for Error Handling

Errors from the Activate Billing Contracts Apex action are not recorded in logs. If you want to capture errors and email them to the user, you can store the return values in resources which are available to other flow elements. For an illustration of how to do this, see Sample Flows to Activate Contracts.

When configuring the action in a flow, click Advanced and select the Manually Assign Variables checkbox to store the following return values.

Output Variable

Description

Billing Contract ID to be activated ID of the contract that has been processed.
Has Errors

Assign this to a boolean variable to store the outcome of the activation action, so that it can be used by a Decision element later in the flow.

Errors while activating this contract Assign this to a text variable which can be used to store any resulting error messages so that an Action element can email them to the user.

Inputs and Outputs for the Activate Billing Contracts Asynchronously Apex Action

Input Parameters

The Activate Billing Contracts Asynchronously Apex action has the following input parameters for each billing contract passed to it.

Parameter

Required or Optional

Description

Billing Contract ID to be activated Required ID of the contract to be activated.

Output Values

The Activate Billing Contracts Asynchronously Apex action records errors in Billing Central logs.

When configuring the action in a flow, click Advanced and select the Manually Assign Variables checkbox to store the following return values.

Output Variable

Description

Billing Contract ID to be activated ID of the contract that has been queued for activation.
Background Process ID ID of the background process that is handling the contract activation.

Permissions

To configure a Salesforce flow to use these Apex actions, you must be assigned a permission set that includes access to the corresponding Apex classes. The classes are included in the following packaged permission set:

  • Billing Central API

A user does not need permission to activate contracts in order to trigger the flow. For example, if you configure the flow to be triggered when a contract's Approval Status changes to "Approved", the flow will be triggered when a user approves the contract even if they do not have permission to activate contracts. However for billing schedules to be generated, the user who triggers the flow must be assigned the following packaged permission set:

  • Billing Central - Contract - Generate Billing Schedules

For more information about creating Salesforce flows, see the Salesforce Help.

Sample Flows to Activate Contracts

For illustrations of how flows can be configured to use these Apex actions, see Sample Flow to Activate a Contract on Approval and Sample Flow to Activate a Collection of Contracts on Approval. These flows do not include error handling. For an illustration of how to build error handling into a flow, see either of the sample flows for renewing contracts at Sample Flows to Renew Contracts.

Note:

The sample flow descriptions do not give step-by-step instructions on how to create the flows. The information is intended for administrators who are already experienced at creating Salesforce flows. Refer to the Salesforce Help if you need information about how to create flows.