deepCloneGroupCensus(groupCensusDeepCloneInputRepresentation, censusId)

Clone a group census and its hierarchy, including members, member plans, and plan attributes. Use this method to copy quoting-phase census data into an enrollment-type census, apply field-level overrides, and optionally filter or remap member plan references.

API Version

68.0

Requires Chatter

No

Signature

public static ConnectApi.GroupCensusDeepCloneRepresentation deepCloneGroupCensus(ConnectApi.GroupCensusDeepCloneInputRepresentation groupCensusDeepCloneInputRepresentation, String censusId)

Parameters

groupCensusDeepCloneInputRepresentation
Type: ConnectApi.GroupCensusDeepCloneInputRepresentation
Details of the clone operation, including optional filters, reference mappings, field overrides, and a custom context definition.
censusId
Type: String
ID of the source group census to clone.

Usage

Use this method to clone a group census and its hierarchy, including members, member plans, and plan attributes. Specify the source census in censusId. All properties on the input representation are optional.

To clone only the member plans that belong to a quote, set quoteId on memberPlanFilter. To remap those plans from quote line items to contract group plans, set contractId on memberPlanReferenceMapping. To stamp new field values on the cloned census, put field API names and values in targetGroupCensusOverrides.

To clone the full hierarchy with no filters, mappings, or overrides, pass an empty input representation. The method runs asynchronously. Use the requestId in the response to track the job. Errors that occur while validating or scheduling the job are in the errors property.

Example

This is an example to clone a group census from Apex code. It limits the clone to member plans on a specified quote, remaps those quote line item references to contract group plans, and stamps name and status values on the target census.

1// Clone a group census hierarchy, optionally filtering member plans,
2// remapping references, and stamping field values on the target census.
3
4final String CENSUS_ID = '0rfxx000000022IAAQ';
5final String SOURCE_QUOTE_ID = '0Q0xx0000004C92CAE';
6final String TARGET_CONTRACT_ID = '800xx000000gVN3AAM';
7
8// Optional: scope the clone to one quote's member plans.
9ConnectApi.MemberPlanFilterInputRepresentation memberPlanFilter =
10    new ConnectApi.MemberPlanFilterInputRepresentation();
11memberPlanFilter.quoteId = SOURCE_QUOTE_ID;
12
13ConnectApi.GroupCensusFiltersInputRepresentation groupCensusFilters =
14    new ConnectApi.GroupCensusFiltersInputRepresentation();
15groupCensusFilters.memberPlanFilter = memberPlanFilter;
16
17// Optional: remap quote line items to contract group plans.
18// Provide exactly the direction you want.
19ConnectApi.MemberPlanReferenceMappingInputRepresentation memberPlanReferenceMapping =
20    new ConnectApi.MemberPlanReferenceMappingInputRepresentation();
21memberPlanReferenceMapping.contractId = TARGET_CONTRACT_ID;
22
23ConnectApi.GroupCensusReferenceMappingsInputRepresentation groupCensusReferenceMappings =
24    new ConnectApi.GroupCensusReferenceMappingsInputRepresentation();
25groupCensusReferenceMappings.memberPlanReferenceMapping = memberPlanReferenceMapping;
26
27ConnectApi.GroupCensusDeepCloneInputRepresentation input =
28    new ConnectApi.GroupCensusDeepCloneInputRepresentation();
29input.groupCensusFilters = groupCensusFilters;
30input.groupCensusReferenceMappings = groupCensusReferenceMappings;
31input.targetGroupCensusOverrides = new Map<String, Object>{
32    'Name' => 'Apex DeepClone Census',
33    'Status' => 'Draft'
34};
35// input.contextDefId = 'My_Custom_DeepClone_ContextDef';   // optional
36
37try {
38    ConnectApi.GroupCensusDeepCloneRepresentation result =
39        ConnectApi.GroupBenefitsApi.deepCloneGroupCensus(input, CENSUS_ID);
40
41    System.debug('requestId: ' + result.requestId);
42    System.debug('errors: ' + result.errors);
43} catch (Exception e) {
44    System.debug('Error while cloning the group census: ' + e.getMessage());
45}

This example clones the full hierarchy with no filters, mappings, or overrides.

1// Clone the full census hierarchy with no filters, mappings, or overrides.
2
3final String CENSUS_ID = '0rfxx000000022IAAQ';
4
5ConnectApi.GroupCensusDeepCloneInputRepresentation input =
6    new ConnectApi.GroupCensusDeepCloneInputRepresentation();
7
8try {
9    ConnectApi.GroupCensusDeepCloneRepresentation result =
10        ConnectApi.GroupBenefitsApi.deepCloneGroupCensus(input, CENSUS_ID);
11
12    System.debug('requestId: ' + result.requestId);
13    System.debug('errors: ' + result.errors);
14} catch (Exception e) {
15    System.debug('Error while cloning the group census: ' + e.getMessage());
16}