cancelInsurancePolicy(insurancePolicyCancelInput, policyId)

Cancel a specific insurance policy by providing the cancellation details and the policy ID.

API Version

67.0

Requires Chatter

No

Signature

public static ConnectApi.InsurancePolicyCancellationRepresentation cancelInsurancePolicy(ConnectApi.InsurancePolicyCancellationInputRepresentation insurancePolicyCancelInput, String policyId)

Parameters

insurancePolicyCancelInput

policyId

  • Type: String
  • ID of the insurance policy to cancel.

Usage

Use this method to cancel a specific insurance policy. Provide the cancellation effective date, reason, and target status in the input representation, along with the ID of the policy to cancel. The policy is canceled synchronously, and the response includes the transaction ID, impacted policy versions, and any errors.

Example

The Apex example shows how to use the ConnectApi.InsuranceBrokerageFamily.cancelInsurancePolicy() method to cancel a specific insurance policy.

Class Definition

This Apex example shows how to cancel an insurance policy.

global class CancelConnectDriver {

    global static void callCancelConnectAPI() {
        Map<String, Object> input = new Map<String, Object>();
        input.put('policyId', '0YTxx000000001dGAA');

        ConnectApi.InsurancePolicyCancellationInputRepresentation cancelInput = new ConnectApi.InsurancePolicyCancellationInputRepresentation();
        cancelInput.cancellationEffectiveDate = '2026-07-01';
        cancelInput.status = 'Cancelled';
        cancelInput.cancellationReason = 'Customer Request';

        input.put('policyInput', cancelInput);

        Map<String, Object> output = new Map<String, Object>();
        Map<String, Object> args = new Map<String, Object>();
        args.put('input', input);
        args.put('output', output);

        CancelTestConnectAPI callable = new CancelTestConnectAPI();
        Object result = callable.call('cancel', args);

        ConnectApi.InsurancePolicyCancellationRepresentation policyData =
            (ConnectApi.InsurancePolicyCancellationRepresentation) result;
        System.debug('Cancel Policy Data: ' + JSON.serializePretty(policyData));

        if (output.containsKey('error')) {
            System.debug('Error: ' + output.get('error'));
        }
    }
}

Usage Example

Use the CancelTestConnectAPI class to execute the cancel action and process the result.

public class CancelTestConnectAPI implements System.Callable {

    public Object call(String action, Map<String, Object> args) {
        Map<String, Object> inputMap = (Map<String, Object>) args.get('input');
        Map<String, Object> outputMap = (Map<String, Object>) args.get('output');

        if (action == 'cancel') {
            ConnectApi.InsurancePolicyCancellationInputRepresentation cancelInput =
                (ConnectApi.InsurancePolicyCancellationInputRepresentation) inputMap.get('policyInput');
            String policyId = (String) inputMap.get('policyId');
            System.debug('Start of Connect API call to cancel policy: ' + policyId);

            ConnectApi.InsurancePolicyCancellationRepresentation policyData;
            try {
                policyData = ConnectApi.InsuranceBrokerageFamily.cancelInsurancePolicy(cancelInput, policyId);
                System.debug('Policy cancelled successfully: ' + policyData);
                outputMap.put('policyData', policyData);
            } catch (Exception e) {
                System.debug('Error while cancelling policy: ' + e.getMessage());
                outputMap.put('error', e.getMessage());
            }
            return policyData;
        }

        return null;
    }
}

// Execute
CancelConnectDriver.callCancelConnectAPI();