Newer Version Available
MultiRootRenewPolicy(RenewPolicyInput, policyId)
Asynchronouly renew a multi-root insurance policy, create renewed records for the parent
policy and the associated child policies. Use the priced context ID for the renewal
process.
API Version
66.0
Requires Chatter
No
Signature
public static ConnectApi.PolicyAsyncRepresentation MultiRootRenewPolicy(ConnectApi.RenewPolicyInputRepresentation RenewPolicyInput, String policyId)
Parameters
- RenewPolicyInput
- Type: ConnectApi.RenewPolicyInputRepresentation
- Input representation of the request to renew an existing multi-root policy.
- policyId
- Type: String
- ID of the multi-root policy that must be renewed along with its child policies.
Return Value
Example
This is a sample code that calls the Multi-Root Policy Renewal API from Apex.
1
2public with sharing class MultiRootPolicyRenewal implements System.Callable {
3
4 public Object call(String action, Map<String, Object> args) {
5 // Retrieve the input and output maps from the arguments
6 Map<String, Object> inputMap = (Map<String, Object>) args.get('input');
7 Map<String, Object> outputMap = (Map<String, Object>) args.get('output');
8
9 // Check the action type
10 if (action == 'multiRootRenewPolicy') {
11 System.debug('Start of connect API call to multi-root renew policy');
12
13 // Get input parameters from the input map
14 String contextId = (String) inputMap.get('contextId');
15 String policyId = (String) inputMap.get('policyId');
16 String policyName = (String) inputMap.get('policyName');
17 String policyNumber = (String) inputMap.get('policyNumber');
18 String effectiveFromDate = (String) inputMap.get('effectiveFromDate');
19 String effectiveToDate = (String) inputMap.get('effectiveToDate');
20 String transactionName = (String) inputMap.get('transactionName');
21 Map<String, Object> additionalFields = (Map<String, Object>) inputMap.get('additionalFields');
22
23 System.debug('Context ID: ' + contextId);
24 System.debug('Policy ID: ' + policyId);
25 System.debug('Policy Name: ' + policyName);
26 System.debug('Policy Number: ' + policyNumber);
27 System.debug('Effective From Date: ' + effectiveFromDate);
28 System.debug('Effective To Date: ' + effectiveToDate);
29 System.debug('Transaction Name: ' + transactionName);
30 System.debug('Additional Fields: ' + additionalFields);
31
32 // Initialize the job identifier
33 String jobIdentifier = null;
34
35 // Validate required parameters
36 if (String.isBlank(contextId)) {
37 System.debug('ERROR: Context ID is required');
38 outputMap.put('error', 'Context ID is required');
39 return null;
40 }
41
42 if (String.isBlank(policyId)) {
43 System.debug('ERROR: Policy ID is required');
44 outputMap.put('error', 'Policy ID is required');
45 return null;
46 }
47
48 try {
49
50 // Step 1: Create Multi-Root Policy Renewal input using the provided context ID
51 ConnectApi.RenewPolicyInputRepresentation renewalInput =
52 new ConnectApi.RenewPolicyInputRepresentation();
53
54 // Use the provided context ID (REQUIRED)
55 renewalInput.contextId = contextId;
56
57 // Populate fields for InsurancePolicyInputRepresentation (nested object)
58 ConnectApi.InsurancePolicyInputRepresentation insurancePolicy =
59 new ConnectApi.InsurancePolicyInputRepresentation();
60
61 // Set policy basic fields (all optional)
62 if (!String.isBlank(policyName)) {
63 insurancePolicy.policyName = policyName;
64 }
65 if (!String.isBlank(policyNumber)) {
66 insurancePolicy.policyNumber = policyNumber;
67 }
68
69 // Set effective dates on the insurancePolicy object (not on renewalInput directly)
70 if (!String.isBlank(effectiveFromDate)) {
71 insurancePolicy.effectiveFromDate = effectiveFromDate;
72 }
73 if (!String.isBlank(effectiveToDate)) {
74 insurancePolicy.effectiveToDate = effectiveToDate;
75 }
76
77 // Only set insurancePolicy if any fields were set
78 if (!String.isBlank(policyName) || !String.isBlank(policyNumber) ||
79 !String.isBlank(effectiveFromDate) || !String.isBlank(effectiveToDate)) {
80 renewalInput.insurancePolicy = insurancePolicy;
81 }
82
83 // Populate transaction record (optional)
84 if (!String.isBlank(transactionName)) {
85 ConnectApi.InsurancePolicyTransactionInputRepresentation transactionRecord =
86 new ConnectApi.InsurancePolicyTransactionInputRepresentation();
87 transactionRecord.name = transactionName;
88 renewalInput.transactionRecord = transactionRecord;
89 }
90
91 // Populate additional fields for child policies
92 if (additionalFields != null && !additionalFields.isEmpty()) {
93 System.debug('Processing additional fields for child policies');
94 renewalInput.additionalFields = buildAdditionalFieldsList(additionalFields);
95 }
96
97 // Step 2: Execute Multi-Root Policy Renewal with the provided context ID and policy ID
98 System.debug('Executing Multi-Root Policy Renewal with context ID: ' + contextId + ' and policy ID: ' + policyId);
99
100 // Call the Connect API - Multi-Root Renewal is ASYNCHRONOUS and returns a job identifier
101 // NOTE: Parameter order is INPUT first, then policyId
102 ConnectApi.PolicyAsyncRepresentation renewalResult =
103 ConnectApi.InsurancePolicyAdminFamily.multiRootRenewPolicy(renewalInput, policyId);
104
105 // Get the job identifier
106 jobIdentifier = renewalResult.jobIdentifier;
107
108 // Log success
109 System.debug('Multi-root policy renewal job started successfully. Job ID: ' + jobIdentifier);
110 System.debug('Context: ' + contextId);
111 System.debug('Policy ID: ' + policyId);
112
113 // Put the job identifier in the output map
114 outputMap.put('jobIdentifier', jobIdentifier);
115 outputMap.put('renewalResult', renewalResult);
116
117 } catch (Exception e) {
118 System.debug('Error while executing multi-root policy renewal: ' + e.getMessage());
119 System.debug('Stack Trace: ' + e.getStackTraceString());
120 outputMap.put('error', e.getMessage());
121 }
122
123 // Return the job identifier
124 return jobIdentifier;
125 }
126
127 // If the action is not recognized, return null
128 return null;
129 }
130
131
132 /**
133 * Build additional fields list for multi-root policies
134 * Converts from Map structure to List<ConnectApi.AdditionalFieldsMapValue>
135 *
136 * Input structure:
137 * {
138 * "additionalFieldsList": [
139 * {
140 * "additionalFieldsMapValue": {
141 * "instanceKey": "AutoSilver",
142 * "fields": { "EffectiveFromDate": "2025-01-01", "EffectiveToDate": "2026-01-01"}
143 * }
144 * }
145 * ]
146 * }
147 */
148 private static List<ConnectApi.AdditionalFieldsMapValue> buildAdditionalFieldsList(Map<String, Object> additionalFieldsInput) {
149 List<ConnectApi.AdditionalFieldsMapValue> fieldsList = new List<ConnectApi.AdditionalFieldsMapValue>();
150
151 // Get the additionalFieldsList array
152 List<Object> additionalFieldsList = (List<Object>) additionalFieldsInput.get('additionalFieldsList');
153
154 if (additionalFieldsList != null && !additionalFieldsList.isEmpty()) {
155 for (Object item : additionalFieldsList) {
156 Map<String, Object> itemMap = (Map<String, Object>) item;
157 Object mapValue = itemMap.get('additionalFieldsMapValue');
158
159 if (mapValue != null) {
160 // Create ConnectApi.AdditionalFieldsMapValue instance
161 ConnectApi.AdditionalFieldsMapValue fieldMapValue = new ConnectApi.AdditionalFieldsMapValue();
162
163 // Set the additionalFieldsMapValue property
164 // This property accepts Object type which will be the Map containing instanceKey and fields
165 fieldMapValue.additionalFieldsMapValue = mapValue;
166
167 fieldsList.add(fieldMapValue);
168 }
169 }
170 }
171
172 return fieldsList;
173 }
174}
175
176/*
177 * USAGE EXAMPLE:
178 * Copy and paste this code into Developer Console Execute Anonymous Window
179 */
180
181// Create instance of the callable class
182MultiRootPolicyRenewal callable = new MultiRootPolicyRenewal();
183
184// Build additional fields for child policies
185// Structure matches the JSON payload exactly
186Map<String, Object> additionalFields = new Map<String, Object>();
187List<Object> additionalFieldsList = new List<Object>();
188
189// Child Policy 1: Auto Insurance
190Map<String, Object> autoPolicy = new Map<String, Object>();
191Map<String, Object> autoMapValue = new Map<String, Object>();
192autoMapValue.put('instanceKey', 'AutoSilver');
193Map<String, Object> autoFields = new Map<String, Object>();
194autoFields.put('PolicyName', 'James Auto Policy');
195autoFields.put('Name', 'James Auto Policy');
196autoMapValue.put('fields', autoFields);
197autoPolicy.put('additionalFieldsMapValue', autoMapValue);
198additionalFieldsList.add(autoPolicy);
199
200// Child Policy 2: Health Insurance
201Map<String, Object> healthPolicy = new Map<String, Object>();
202Map<String, Object> healthMapValue = new Map<String, Object>();
203healthMapValue.put('instanceKey', 'FamilyHealth');
204
205Map<String, Object> healthFields = new Map<String, Object>();
206healthFields.put('PolicyName', 'James Medical Policy');
207healthFields.put('Name', 'James Medical Policy');
208healthMapValue.put('fields', healthFields);
209healthPolicy.put('additionalFieldsMapValue', healthMapValue);
210additionalFieldsList.add(healthPolicy);
211
212additionalFields.put('additionalFieldsList', additionalFieldsList);
213input.put('additionalFields', additionalFields);
214
215// Prepare the input arguments - WITH ADDITIONAL FIELDS
216Map<String, Object> input = new Map<String, Object>();
217input.put('contextId', <your-context-id-here>); // REQUIRED
218input.put('policyId', <your-policy-id-here>); // REQUIRED
219input.put('effectiveFromDate', '2026-01-01'); // Optional
220input.put('effectiveToDate', '2027-01-01'); // Optional
221input.put('policyName', 'Renewed Multi-Root Policy');
222input.put('transactionName', 'Multi-Root Annual Renewal with Updates');
223input.put('additionalFields', additionalFields);
224
225// Prepare the output map
226Map<String, Object> output = new Map<String, Object>();
227
228// Prepare the args map
229Map<String, Object> args = new Map<String, Object>();
230args.put('input', input);
231args.put('output', output);
232
233// Call the 'multiRootRenewPolicy' action
234Object result = callable.call('multiRootRenewPolicy', args);
235
236// Check results
237if (output.containsKey('error')) {
238 System.debug('ERROR: ' + output.get('error'));
239} else if (output.containsKey('jobIdentifier')) {
240 String jobId = (String) output.get('jobIdentifier');
241 System.debug('SUCCESS: Multi-root renewal job started with Job ID: ' + jobId);
242 System.debug('Use this job ID to track the renewal progress');
243}