Newer Version Available

This content describes an older version of this product. View Latest

MultiRootEndorsePolicy(EndorsePolicyInput, policyId)

Resource for the Insurance Multi Root Endorsement Policy Connect API POST Method.

API Version

66.0

Requires Chatter

No

Signature

public static ConnectApi.PolicyAsyncRepresentation MultiRootEndorsePolicy(ConnectApi.EndorsePolicyInputRepresentation EndorsePolicyInput, String policyId)

Parameters

EndorsePolicyInput
Type: ConnectApi.EndorsePolicyInputRepresentation
Details to endorse the multi-root insurance policy along with its child policies.
policyId
Type: String
ID of the insurance policy that must be endorsed along with its child policies.

Example

This is a sample code that calls the Multi-Root Policy Endorsement API from Apex.

1
2public with sharing class MultiRootPolicyEndorsement 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 == 'multiRootEndorsePolicy') {
11            System.debug('Start of connect API call to multi-root endorse 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 effectiveDate = (String) inputMap.get('effectiveDate');
19            String transactionName = (String) inputMap.get('transactionName');
20            Map<String, Object> additionalFields = (Map<String, Object>) inputMap.get('additionalFields');
21            
22            System.debug('Context ID: ' + contextId);
23            System.debug('Policy ID: ' + policyId);
24            System.debug('Policy Name: ' + policyName);
25            System.debug('Policy Number: ' + policyNumber);
26            System.debug('Effective Date: ' + effectiveDate);
27            System.debug('Transaction Name: ' + transactionName);
28            System.debug('Additional Fields: ' + additionalFields);
29            
30            // Initialize the job identifier
31            String jobIdentifier = null;
32            
33            // Validate required parameters
34            if (String.isBlank(contextId)) {
35                System.debug('ERROR: Context ID is required');
36                outputMap.put('error', 'Context ID is required');
37                return null;
38            }
39            
40            try {
41                
42                // Step 1: Create Multi-Root Policy Endorsement input using the provided context ID
43                ConnectApi.EndorsePolicyInputRepresentation policyInput = 
44                    new ConnectApi.EndorsePolicyInputRepresentation();
45                
46                // Populate fields for InsurancePolicyInputRepresentation 
47                ConnectApi.InsurancePolicyInputRepresentation insurancePolicy = 
48                    new ConnectApi.InsurancePolicyInputRepresentation();
49                
50                // Set policy basic fields (all optional except contextId)
51                if (!String.isBlank(policyName)) {
52                    insurancePolicy.policyName = policyName;
53                }
54                if (!String.isBlank(policyNumber)) {
55                    insurancePolicy.policyNumber = policyNumber;
56                }
57                
58                policyInput.insurancePolicy = insurancePolicy;
59                
60                // Populate transaction record (optional)
61                if (!String.isBlank(transactionName)) {
62                    ConnectApi.InsurancePolicyTransactionInputRepresentation transactionRecord = 
63                        new ConnectApi.InsurancePolicyTransactionInputRepresentation();
64                    transactionRecord.name = transactionName;
65                    policyInput.transactionRecord = transactionRecord;
66                }
67                
68                // Use the provided context ID (REQUIRED)
69                policyInput.contextId = contextId;
70             
71                // Use the provided Effective Date (REQUIRED)
72                policyInput.effectiveDate = effectiveDate;
73                
74                // Populate additional fields for child policies
75                if (additionalFields != null && !additionalFields.isEmpty()) {
76                    System.debug('Processing additional fields for child policies');
77                    policyInput.additionalFields = buildAdditionalFieldsList(additionalFields);
78                }
79                
80                // Step 2: Execute Multi-Root Policy Endorsement with the provided context ID
81                System.debug('Executing Multi-Root Policy Endorsement with context ID: ' + contextId + ' policy ID:' + policyId);
82              
83                Id idPolicyId = Id.valueOf(policyId);
84                
85                // Call the Connect API - Multi-Root Endorsement is ASYNCHRONOUS and returns a job identifier
86                ConnectApi.PolicyAsyncRepresentation endorseResult =
87                    ConnectApi.InsurancePolicyAdminFamily.multiRootEndorsePolicy(policyInput, idPolicyId);
88                
89                // Get the job identifier
90                jobIdentifier = endorseResult.jobIdentifier;
91                
92                // Log success
93                System.debug('Multi-root policy endorsement job started successfully. Job ID: ' + jobIdentifier);
94                System.debug('Context: ' + contextId);
95                if (!String.isBlank(policyName)) {
96                    System.debug('Policy Name: ' + policyName);
97                }
98                
99                // Put the job identifier in the output map
100                outputMap.put('jobIdentifier', jobIdentifier);
101                outputMap.put('endorsementResult', endorseResult);
102                
103            } catch (Exception e) {
104                System.debug('Error while executing multi-root policy endorsement: ' + e.getMessage());
105                System.debug('Stack Trace: ' + e.getStackTraceString());
106                outputMap.put('error', e.getMessage());
107            }
108            
109            // Return the job identifier
110            return jobIdentifier;
111        }
112        
113        // If the action is not recognized, return null
114        return null;
115    }
116
117
118    
119    /**
120     * Build additional fields list for multi-root policies
121     * Converts from Map structure to List<ConnectApi.AdditionalFieldsMapValue>
122     * 
123     * Input structure:
124     * {
125     *   "additionalFieldsList": [
126     *     {
127     *       "additionalFieldsMapValue": {
128     *         "instanceKey": "AutoSilver",
129     *         "fields": { "PolicyName": "James Auto Policy"}
130     *       }
131     *     }
132     *   ]
133     * }
134     */
135    private static List<ConnectApi.AdditionalFieldsMapValue> buildAdditionalFieldsList(Map<String, Object> additionalFieldsInput) {
136        List<ConnectApi.AdditionalFieldsMapValue> fieldsList = new List<ConnectApi.AdditionalFieldsMapValue>();
137        
138        // Get the additionalFieldsList array
139        List<Object> additionalFieldsList = (List<Object>) additionalFieldsInput.get('additionalFieldsList');
140        
141        if (additionalFieldsList != null && !additionalFieldsList.isEmpty()) {
142            for (Object item : additionalFieldsList) {
143                Map<String, Object> itemMap = (Map<String, Object>) item;
144                Object mapValue = itemMap.get('additionalFieldsMapValue');
145                
146                if (mapValue != null) {
147                    // Create ConnectApi.AdditionalFieldsMapValue instance
148                    ConnectApi.AdditionalFieldsMapValue fieldMapValue = new ConnectApi.AdditionalFieldsMapValue();
149                    
150                    // Set the additionalFieldsMapValue property
151                    // This property accepts Object type which will be the Map containing instanceKey and fields
152                    fieldMapValue.additionalFieldsMapValue = mapValue;
153                    
154                    fieldsList.add(fieldMapValue);
155                }
156            }
157        }
158        
159        return fieldsList;
160    }
161}
162
163/*
164 * USAGE EXAMPLE:
165 * Multi-Root Policy Endorsement with Additional Fields
166 */
167
168// Create instance of the callable class
169MultiRootPolicyEndorsement callable = new MultiRootPolicyEndorsement();
170
171// Prepare the input arguments with additional fields
172Map<String, Object> input = new Map<String, Object>();
173input.put('contextId', '0000000i18tq18g002917629263342460535451b25974898aae9a44aab48ef3c'); // REQUIRED - Replace with your context ID
174input.put('policyId', '0YTSM0000001MrJ4AU'); // REQUIRED - Replace with your policy ID
175input.put('policyName', 'James Multi-Root Policy');
176input.put('policyNumber', 'James Multi-Root Policy');
177input.put('referencePolicyNumber', 'James1234');
178input.put('effectiveDate', '2025-08-30'); // REQUIRED
179input.put('transactionName', 'Endorsed Policy Transaction');
180
181// Build additional fields for child policies
182// Structure matches the JSON payload exactly
183Map<String, Object> additionalFields = new Map<String, Object>();
184List<Object> additionalFieldsList = new List<Object>();
185
186// Child Policy 1: Auto Insurance
187Map<String, Object> autoPolicy = new Map<String, Object>();
188Map<String, Object> autoMapValue = new Map<String, Object>();
189autoMapValue.put('instanceKey', 'AutoSilver');
190Map<String, Object> autoFields = new Map<String, Object>();
191autoFields.put('PolicyName', 'James Auto Policy');
192autoFields.put('Name', 'James Auto Policy');
193autoMapValue.put('fields', autoFields);
194autoPolicy.put('additionalFieldsMapValue', autoMapValue);
195additionalFieldsList.add(autoPolicy);
196
197// Child Policy 2: Health Insurance
198Map<String, Object> healthPolicy = new Map<String, Object>();
199Map<String, Object> healthMapValue = new Map<String, Object>();
200healthMapValue.put('instanceKey', 'FamilyHealth');
201
202Map<String, Object> healthFields = new Map<String, Object>();
203healthFields.put('PolicyName', 'James Medical Policy');
204healthFields.put('Name', 'James Medical Policy');
205healthMapValue.put('fields', healthFields);
206healthPolicy.put('additionalFieldsMapValue', healthMapValue);
207additionalFieldsList.add(healthPolicy);
208
209additionalFields.put('additionalFieldsList', additionalFieldsList);
210input.put('additionalFields', additionalFields);
211
212// Prepare the output map
213Map<String, Object> output = new Map<String, Object>();
214
215// Prepare the args map
216Map<String, Object> args = new Map<String, Object>();
217args.put('input', input);
218args.put('output', output);
219
220// Call the 'multiRootEndorsePolicy' action
221Object result = callable.call('multiRootEndorsePolicy', args);
222
223// Check results
224System.debug('Job Identifier: ' + result);
225if (output.containsKey('error')) {
226    System.debug('ERROR: ' + output.get('error'));
227} else if (output.containsKey('endorsementResult')) {
228    System.debug('SUCCESS: Multi-root policy endorsement job started with ID: ' + output.get('jobIdentifier'));
229    System.debug('This job will endorse the input policy and apply the changes using the context, with additional fields on parent and child policies.');
230    System.debug('Monitor this job ID for completion status.');
231}