---
schema_version: "1"
id: 2a7155602788ff5435f910e7c01a93b5b4c77935f551388ee1b4111141a07b68
title: cancelInsurancePolicy(insurancePolicyCancelInput, policyId)
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/insurance_developer_guide/apex_ConnectAPI_InsuranceBrokerageFamily_cancelInsurancePolicy_1.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.insurance_developer_guide.meta/insurance_developer_guide/apex_ConnectAPI_InsuranceBrokerageFamily_cancelInsurancePolicy_1.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 4205e92fabf26aaa8aaf7321bcecbfa5981aba8f2539b07648a1a1562b01b948
description: Cancel a specific insurance policy by providing the cancellation details and the policy ID.
---
# 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**

- Type: [ConnectApi.InsurancePolicyCancellation​InputRepresentation](https://developer.salesforce.com/docs/atlas.en-us.insurance_developer_guide.meta/insurance_developer_guide/apex_connectapi_input_insurance_policy_cancellation.htm "Input representation for the cancel policy request. Includes the cancellation effective date, the cancellation reason, and the target status for the canceled policy.")
- Input representation containing the cancellation effective date, reason, and target status for the canceled policy.

**policyId**

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

## Return Value

Type: [ConnectApi.InsurancePolicyCancellationRepresentation](https://developer.salesforce.com/docs/atlas.en-us.insurance_developer_guide.meta/insurance_developer_guide/apex_connectapi_output_insurance_policy_cancellation.htm "Output representation for the cancel policy response. Contains the transaction ID, a list of impacted policy versions, and any errors that occurred during the cancellation process.")

## 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();