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)
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.34final String CENSUS_ID = '0rfxx000000022IAAQ';5final String SOURCE_QUOTE_ID = '0Q0xx0000004C92CAE';6final String TARGET_CONTRACT_ID = '800xx000000gVN3AAM';78// Optional: scope the clone to one quote's member plans.9ConnectApi.MemberPlanFilterInputRepresentation memberPlanFilter =10 new ConnectApi.MemberPlanFilterInputRepresentation();11memberPlanFilter.quoteId = SOURCE_QUOTE_ID;1213ConnectApi.GroupCensusFiltersInputRepresentation groupCensusFilters =14 new ConnectApi.GroupCensusFiltersInputRepresentation();15groupCensusFilters.memberPlanFilter = memberPlanFilter;1617// 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;2223ConnectApi.GroupCensusReferenceMappingsInputRepresentation groupCensusReferenceMappings =24 new ConnectApi.GroupCensusReferenceMappingsInputRepresentation();25groupCensusReferenceMappings.memberPlanReferenceMapping = memberPlanReferenceMapping;2627ConnectApi.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'; // optional3637try{38 ConnectApi.GroupCensusDeepCloneRepresentation result =39 ConnectApi.GroupBenefitsApi.deepCloneGroupCensus(input, CENSUS_ID);4041 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.23final String CENSUS_ID = '0rfxx000000022IAAQ';45ConnectApi.GroupCensusDeepCloneInputRepresentation input =6 new ConnectApi.GroupCensusDeepCloneInputRepresentation();78try{9 ConnectApi.GroupCensusDeepCloneRepresentation result =10 ConnectApi.GroupBenefitsApi.deepCloneGroupCensus(input, CENSUS_ID);1112 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}