---
schema_version: "1"
id: ad2418b76eb5dbd1cb24d7c7a1876174ebea698c6291858a2ea4d9b569f9c1b2
title: postInsuranceCreateCensus(createCensusInputParam, contractId)
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/insurance_developer_guide/apex_ConnectAPI_InsuranceGroupBenefitsFamily_postInsuranceCreateCensus.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.insurance_developer_guide.meta/insurance_developer_guide/apex_ConnectAPI_InsuranceGroupBenefitsFamily_postInsuranceCreateCensus.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: dcf47358b1d5f01c7506e16e33df43ccce22eb668eda0662c58a541eec7e302c
description: Generate a group census from the policies on an existing group benefits contract.
---
# postInsuranceCreateCensus(createCensusInputParam, contractId)

Generate a group census from the policies on an existing group benefits contract.

## API Version

67.0

## Requires Chatter

No

## Signature

public static ConnectApi.InsuranceGenerateCensusRepresentation postInsuranceCreateCensus(ConnectApi.InsuranceGenerateCensusInputRepresentation createCensusInputParam, String contractId)

## Parameters

**createCensusInputParam**

- Type: [ConnectApi.InsuranceGenerateCensusInputRepresentation](https://developer.salesforce.com/docs/atlas.en-us.insurance_developer_guide.meta/insurance_developer_guide/apex_connectapi_input_insurance_generate_census.htm "Input representation of the census name and type, optional policy date, filters, and generation options used to create a group census from the policies on a contract.")
- Census name and type, optional policy date, filters, and generation options used to create the group census.

**contractId**

- Type: String
- ID of the insurance contract whose policies are used to generate the group census.

## Return Value

Type: [ConnectApi.InsuranceGenerateCensusRepresentation](https://developer.salesforce.com/docs/atlas.en-us.insurance_developer_guide.meta/insurance_developer_guide/apex_connectapi_output_insurance_generate_census.htm "Output representation that's returned when you start generating a group census from the policies on a group benefits contract.")

## Usage

Use this method to generate a group census from the policies on an existing group benefits contract. Specify the contract in contractId and the census type in censusType, such as Enrollment or Quote. Optionally set censusName.

This method runs asynchronously and returns a requestId that you can use to track the job. To retry a failed run, pass that requestId on the next call.

Set policyEffectiveDate in yyyy-MM-dd format to select the policy version. The date must fall between the version's effectiveFromDate and effectiveToDate. Use filter to limit the census to root contract group plans, contacts, or person accounts. Set shouldGenerateCsv to create a CSV file of the census details. Set shouldIncludeMemberPlans to include insurance plan details for each member.

Check isSuccess, groupCensusId, and requestId on the response. Errors are in the errors property.

## Example

This example starts generating an enrollment census from a contract, filters by person account, and includes member plan details and a CSV file.

// Generate a group census from the policies on a contract.

final String CONTRACT\_ID = '800SB00001I80hWYAR';

// Optional: filter by members and/or root contract group plans.
ConnectApi.InsuranceCensusFilterInputRepresentation filter =
    new ConnectApi.InsuranceCensusFilterInputRepresentation();
filter.objectName = 'PersonAccount';   // Contact or PersonAccount
filter.recordIds = new List<String\>{ '001SB00001xuR1RYAU' };
// filter.contractGroupPlanIds = new List<String>{ /\* CGP ids \*/ };

ConnectApi.InsuranceGenerateCensusInputRepresentation input =
    new ConnectApi.InsuranceGenerateCensusInputRepresentation();
input.censusName = 'apex\_Census';
input.censusType = 'Enrollment';  // e.g. System, Quote, Enrollment, Lead, Renewal
// input.policyEffectiveDate = '2027-09-01';  // yyyy-MM-dd
input.shouldGenerateCsv = true;
input.shouldIncludeMemberPlans = true;
input.filter = filter;
// input.requestId = '08Pxx0000000001EAA';  // only to retry a previously failed job

try {
    ConnectApi.InsuranceGenerateCensusRepresentation result =
        ConnectApi.InsuranceGroupBenefitsFamily.postInsuranceCreateCensus(input, CONTRACT\_ID);

    System.debug('isSuccess: ' + result.isSuccess);
    System.debug('groupCensusId: ' + result.groupCensusId);
    System.debug('requestId: ' + result.requestId);
    System.debug('message: ' + result.message);
    System.debug('errors: ' + result.errors);
} catch (Exception e) {
    System.debug('Error while generating the census: ' + e.getMessage());
}