Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
MultiRootIssuePolicy(IssuePolicyInput)
Asynchronously create a multi-root insurance policy along with its child
policies.
API Version
66.0
Requires Chatter
No
Signature
public static ConnectApi.PolicyAsyncRepresentation MultiRootIssuePolicy(ConnectApi.IssuePolicyInputRepresentation IssuePolicyInput)
Parameters
- IssuePolicyInput
- Type: ConnectApi.IssuePolicyInputRepresentation
- Details to create the multi-root insurance policy.
Return Value
Example
This is a sample code that calls the Multi-Root Issue Policy API from Apex.
1
2public with sharing class MultiRootPolicyIssuance 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 == 'multiRootIssuePolicy') {
11 System.debug('Start of connect API call to multi-root issue policy');
12
13 // Get input parameters from the input map
14 String contextId = (String) inputMap.get('contextId');
15 String policyName = (String) inputMap.get('policyName');
16 String policyNumber = (String) inputMap.get('policyNumber');
17 String referencePolicyNumber = (String) inputMap.get('referencePolicyNumber');
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 Name: ' + policyName);
25 System.debug('Policy Number: ' + policyNumber);
26 System.debug('Reference Policy Number: ' + referencePolicyNumber);
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 try {
43
44 // Step 1: Create Multi-Root Policy Issuance input using the provided context ID
45 ConnectApi.IssuePolicyInputRepresentation policyInput =
46 new ConnectApi.IssuePolicyInputRepresentation();
47
48 // Populate fields for InsurancePolicyInputRepresentation
49 ConnectApi.InsurancePolicyInputRepresentation insurancePolicy =
50 new ConnectApi.InsurancePolicyInputRepresentation();
51
52 // Set policy basic fields (all optional except contextId)
53 if (!String.isBlank(policyName)) {
54 insurancePolicy.policyName = policyName;
55 }
56 if (!String.isBlank(policyNumber)) {
57 insurancePolicy.policyNumber = policyNumber;
58 }
59 if (!String.isBlank(referencePolicyNumber)) {
60 insurancePolicy.referencePolicyNumber = referencePolicyNumber;
61 }
62 if (!String.isBlank(effectiveFromDate)) {
63 insurancePolicy.effectiveFromDate = effectiveFromDate;
64 }
65 if (!String.isBlank(effectiveToDate)) {
66 insurancePolicy.effectiveToDate = effectiveToDate;
67 }
68
69 policyInput.insurancePolicy = insurancePolicy;
70
71 // Populate transaction record (optional)
72 if (!String.isBlank(transactionName)) {
73 ConnectApi.InsurancePolicyTransactionInputRepresentation transactionRecord =
74 new ConnectApi.InsurancePolicyTransactionInputRepresentation();
75 transactionRecord.name = transactionName;
76 policyInput.transactionRecord = transactionRecord;
77 }
78
79 // Use the provided context ID (REQUIRED)
80 policyInput.contextId = contextId;
81
82 // Populate additional fields for child policies
83 if (additionalFields != null && !additionalFields.isEmpty()) {
84 System.debug('Processing additional fields for child policies');
85 policyInput.additionalFields = buildAdditionalFieldsList(additionalFields);
86 }
87
88 // Step 2: Execute Multi-Root Policy Issuance with the provided context ID
89 System.debug('Executing Multi-Root Policy Issuance with context ID: ' + contextId);
90
91 // Call the Connect API - Multi-Root Issuance is ASYNCHRONOUS and returns a job identifier
92 ConnectApi.PolicyAsyncRepresentation issuanceResult =
93 ConnectApi.InsurancePolicyAdminFamily.multiRootIssuePolicy(policyInput);
94
95 // Get the job identifier
96 jobIdentifier = issuanceResult.jobIdentifier;
97
98 // Log success
99 System.debug('Multi-root policy issuance job started successfully. Job ID: ' + jobIdentifier);
100 System.debug('Context: ' + contextId);
101 if (!String.isBlank(policyName)) {
102 System.debug('Policy Name: ' + policyName);
103 }
104
105 // Put the job identifier in the output map
106 outputMap.put('jobIdentifier', jobIdentifier);
107 outputMap.put('issuanceResult', issuanceResult);
108
109 } catch (Exception e) {
110 System.debug('Error while executing multi-root policy issuance: ' + e.getMessage());
111 System.debug('Stack Trace: ' + e.getStackTraceString());
112 outputMap.put('error', e.getMessage());
113 }
114
115 // Return the job identifier
116 return jobIdentifier;
117 }
118
119 // If the action is not recognized, return null
120 return null;
121 }
122
123 /**
124 * Build additional fields list for multi-root policies
125 * Converts from Map structure to List<ConnectApi.AdditionalFieldsMapValue>
126 *
127 * Input structure:
128 * {
129 * "additionalFieldsList": [
130 * {
131 * "additionalFieldsMapValue": {
132 * "instanceKey": "AutoSilver",
133 * "fields": { "PolicyName": "James Auto Policy"}
134 * }
135 * }
136 * ]
137 * }
138 */
139 private static List<ConnectApi.AdditionalFieldsMapValue> buildAdditionalFieldsList(Map<String, Object> additionalFieldsInput) {
140 List<ConnectApi.AdditionalFieldsMapValue> fieldsList = new List<ConnectApi.AdditionalFieldsMapValue>();
141
142 // Get the additionalFieldsList array
143 List<Object> additionalFieldsList = (List<Object>) additionalFieldsInput.get('additionalFieldsList');
144
145 if (additionalFieldsList != null && !additionalFieldsList.isEmpty()) {
146 for (Object item : additionalFieldsList) {
147 Map<String, Object> itemMap = (Map<String, Object>) item;
148 Object mapValue = itemMap.get('additionalFieldsMapValue');
149
150 if (mapValue != null) {
151 // Create ConnectApi.AdditionalFieldsMapValue instance
152 ConnectApi.AdditionalFieldsMapValue fieldMapValue = new ConnectApi.AdditionalFieldsMapValue();
153
154 // Set the additionalFieldsMapValue property
155 // This property accepts Object type which will be the Map containing instanceKey and fields
156 fieldMapValue.additionalFieldsMapValue = mapValue;
157
158 fieldsList.add(fieldMapValue);
159 }
160 }
161 }
162
163 return fieldsList;
164 }
165}
166
167/*
168 * USAGE EXAMPLE:
169 * Multi-Root Policy Issuance with Additional Fields
170 */
171
172// Create instance of the callable class
173MultiRootPolicyIssuance callable = new MultiRootPolicyIssuance();
174
175// Prepare the input arguments with additional fields
176Map<String, Object> input = new Map<String, Object>();
177input.put('contextId', <your-context-id-here>); // REQUIRED - Replace with your context ID
178input.put('policyName', 'James Multi-Root Policy');
179input.put('policyNumber', 'James Multi-Root Policy');
180input.put('referencePolicyNumber', 'James1234');
181input.put('effectiveFromDate', '2026-01-01');
182input.put('effectiveToDate', '2026-10-31');
183input.put('transactionName', 'Sold Policy Transaction');
184
185// Build additional fields for child policies
186// Structure matches the JSON payload exactly
187Map<String, Object> additionalFields = new Map<String, Object>();
188List<Object> additionalFieldsList = new List<Object>();
189
190// Child Policy 1: Auto Insurance
191Map<String, Object> autoPolicy = new Map<String, Object>();
192Map<String, Object> autoMapValue = new Map<String, Object>();
193autoMapValue.put('instanceKey', <instance-key>);
194Map<String, Object> autoFields = new Map<String, Object>();
195autoFields.put('PolicyName', 'James Auto Policy');
196autoFields.put('Name', 'James Auto Policy');
197autoMapValue.put('fields', autoFields);
198autoPolicy.put('additionalFieldsMapValue', autoMapValue);
199additionalFieldsList.add(autoPolicy);
200
201// Child Policy 2: Health Insurance
202Map<String, Object> healthPolicy = new Map<String, Object>();
203Map<String, Object> healthMapValue = new Map<String, Object>();
204healthMapValue.put('instanceKey', <instance-key>);
205
206Map<String, Object> healthFields = new Map<String, Object>();
207healthFields.put('PolicyName', 'James Medical Policy');
208healthFields.put('Name', 'James Medical Policy');
209healthMapValue.put('fields', healthFields);
210healthPolicy.put('additionalFieldsMapValue', healthMapValue);
211additionalFieldsList.add(healthPolicy);
212
213additionalFields.put('additionalFieldsList', additionalFieldsList);
214input.put('additionalFields', additionalFields);
215
216// Prepare the output map
217Map<String, Object> output = new Map<String, Object>();
218
219// Prepare the args map
220Map<String, Object> args = new Map<String, Object>();
221args.put('input', input);
222args.put('output', output);
223
224// Call the 'multiRootIssuePolicy' action
225Object result = callable.call('multiRootIssuePolicy', args);
226
227// Check results
228System.debug('Job Identifier: ' + result);
229if (output.containsKey('error')) {
230 System.debug('ERROR: ' + output.get('error'));
231} else if (output.containsKey('jobIdentifier')) {
232 System.debug('SUCCESS: Multi-root policy issuance job started with ID: ' + output.get('jobIdentifier'));
233 System.debug('This job will create a parent policy and child policies for Auto and Health insurance.');
234 System.debug('Monitor this job ID for completion status.');
235}