---
schema_version: "1"
id: 077d6f7d42ff1ea533724d9d90a37bab819dea5aff9f379e643254ef67ec6fe8
title: |-
  previewPolicyPremium(premiumPreviewInput,
        policyId)
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/insurance_developer_guide/apex_ConnectAPI_InsuranceBrokerageFamily_previewPolicyPremium_1.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.insurance_developer_guide.meta/insurance_developer_guide/apex_ConnectAPI_InsuranceBrokerageFamily_previewPolicyPremium_1.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 5dd5b2131be6dd2287103bfcf52cf215f5444313439821bd28b3468cdb90b2b8
description: Preview prorated and rolled-up premium amounts across a draft insurance policy hierarchy without creating or updating changes.
---
# previewPolicyPremium(premiumPreviewInput, policyId)

Preview prorated and rolled-up premium amounts across a draft insurance policy hierarchy without creating or updating changes.

## API Version

68.0

## Requires Chatter

No

## Signature

public static ConnectApi.PremiumPreviewRepresentation previewPolicyPremium(ConnectApi.PremiumPreviewInputRep premiumPreviewInput, String policyId)

## Parameters

premiumPreviewInput

Type: [ConnectApi.PremiumPreviewInputRep](https://developer.salesforce.com/docs/atlas.en-us.insurance_developer_guide.meta/insurance_developer_guide/apex_connectapi_input_premium_preview_input_rep.htm "Input representation for a draft-state premium preview. Specify hierarchy-node references to compute, or leave the list empty to return only the policy-root amounts.")

Input representation of hierarchy-node references to compute. Omit or leave references empty to get only the policy-root amounts.

policyId

Type: String

ID of the insurance policy (prefix 0YT) to preview premiums for.

## Return Value

Type: [ConnectApi.PremiumPreviewRepresentation](https://developer.salesforce.com/docs/atlas.en-us.insurance_developer_guide.meta/insurance_developer_guide/apex_connectapi_output_premium_preview.htm "Output representation of a draft-state premium preview, including the policy ID and per-node rolled-up amount results.")

## Usage

Use this method when a brokerage sales or service workflow needs to preview rolled-up policy amounts for a Draft insurance policy before issue. Unlike committed lifecycle events such as issue, endorse, cancel, and renew, this method performs a read-only, in-memory calculation. It fetches the policy hierarchy, prorates and rolls up amounts, and returns the calculated amounts without updating roll-up fields, creating IPT or IPTD line items, or triggering billing.

Call this method from Apex or LWC in the same org to make an in-process Connect API call without HTTP session or remote-site configuration. For same-org automation, use this method instead of making an HTTP callout to the REST-based premium-preview resource.

Keep these behaviors in mind.

- **Whole-policy preview:** Pass an empty PremiumPreviewInputRep, or leave the references parameter null or empty to preview the entire policy. The response contains one entry for the policy root.
- **Per-node preview:** Provide up to 2,000 hierarchy-node IDs for policies, assets, participants, coverages, or surcharges. Results are returned in the same order as the requested references. Specify only the nodes you need to keep large-policy previews configurable.
- **Amounts:** Each successful result includes ten double fields on amounts, covering standard and term premium, fee, tax, commission, and totals. The response doesn't include top-level total fields; read amounts from results. For surcharge nodes, only totalStandard and totalTerm may be returned.
- **Per-node failures:** A reference record that isn’t in the hierarchy returns INVALID\_API\_INPUT on that result’s errors list. Other nodes still compute, and the method returns normally.
- **Request-level failures:** Conditions such as a disabled feature gate, invalid policyId, or more than 2000 references show ConnectApi.ConnectApiException. Wrap the call in try/catch when input isn’t trusted.
- **Calculation Parity:** For identical inputs, the returned amounts are intended to match what policy issue computes for the same node, so quoted and issued figures stay aligned.

## Example

These Apex examples show how to call ConnectApi.InsuranceBrokerageFamily.previewPolicyPremium().

**Whole-policy preview (no references)**

Do not specify references so the API response returns a single policy-root entry in results.

Id policyId = '0YTxx000000004rGAA';
// Empty input ⇒ policy-level (root) amounts only.
ConnectApi.PremiumPreviewInputRep input = new ConnectApi.PremiumPreviewInputRep();
ConnectApi.PremiumPreviewRepresentation resp =
    ConnectApi.InsuranceBrokerageFamily.previewPolicyPremium(input, policyId);

// results.size() == 1; the single entry is the policy root.
ConnectApi.PremiumPreviewResultRepresentation root = resp.results\[0\];
System.assertEquals(policyId, root.recordId);
System.debug('totalStandard = ' + root.amounts.totalStandard); // e.g. 2204
System.debug('totalTerm = ' + root.amounts.totalTerm); // e.g. 2164

**Specific hierarchy nodes**

Pass references to return one result per node, in request order.

Id policyId = '0YTxx000000004rGAA';
ConnectApi.PremiumPreviewReferenceRep a1 = new ConnectApi.PremiumPreviewReferenceRep();
a1.recordId = '0YWxx00000000CvGAI'; // Asset A1
ConnectApi.PremiumPreviewReferenceRep p1 = new ConnectApi.PremiumPreviewReferenceRep();
p1.recordId = '0aoxx000000004rAAA'; // Participant P1
ConnectApi.PremiumPreviewInputRep input = new ConnectApi.PremiumPreviewInputRep();
input.references = new List<ConnectApi.PremiumPreviewReferenceRep>{ a1, p1 };
ConnectApi.PremiumPreviewRepresentation resp =
    ConnectApi.InsuranceBrokerageFamily.previewPolicyPremium(input, policyId);

// results\[0\] ⇒ A1, results\[1\] ⇒ P1
for (ConnectApi.PremiumPreviewResultRepresentation r : resp.results) {
    if (r.errors == null) {
        System.debug(r.recordId + ' totalStandard=' + r.amounts.totalStandard);
    } else {
        System.debug(r.recordId + ' FAILED ' + r.errors\[0\].errorCode + ': ' + r.errors\[0\].message);
    }
}

**Per-node failure handling**

A bad references fails only its own result; the method still returns a representation.

Id policyId = '0YTxx000000004rGAA';
ConnectApi.PremiumPreviewReferenceRep bogus = new ConnectApi.PremiumPreviewReferenceRep();
bogus.recordId = '1OPxx0000004C93GAE'; // not a hierarchy node
ConnectApi.PremiumPreviewInputRep input = new ConnectApi.PremiumPreviewInputRep();
input.references = new List<ConnectApi.PremiumPreviewReferenceRep>{ bogus };
ConnectApi.PremiumPreviewRepresentation resp =
    ConnectApi.InsuranceBrokerageFamily.previewPolicyPremium(input, policyId);

ConnectApi.PremiumPreviewResultRepresentation r = resp.results\[0\];
System.assertNotEquals(null, r.errors); // amounts == null, errors populated
System.debug(r.errors\[0\].errorCode); // e.g. INVALID\_API\_INPUT