Create Insurance Rating Action

Create a runtime context that contains the details to create a quote.

This action is available in API version 66.0 and later.

Supported REST HTTP Methods 

URI: /services/data/vXX.X/actions/standard/createInsuranceRating

Where XX.X is the latest API version.

Formats: JSON

HTTP Methods: POST

Authentication: Authorization: Bearer TOKEN

Where TOKEN is your OAuth access token.

Inputs 

InputTypeDescription
additionalFieldsStringAdditional fields to include in the rating context.
effectiveDateDateRequired. Date from which the insurance policy coverage becomes effective.
executeRatingStringIndicates whether rating must be executed ( true ) or not ( false ). The default value is true .
ratingDateDateDate that’s used for rating calculations and rule evaluations. If not specified, the current date is used.
ratingInputsMap<String, Object>Required. JSON string that contains the rating input nodes with product codes and attributes.
ratingOptionsApex-definedAn Apex runtime_industries_insurance.CreateInsuranceRatingOptions record that contains rating execution options to create insurance rating.
rootProductCodesStringArray of root product codes to include in the rating process.
salesTransactionTypeIdStringID of the sales transaction type.
transactionTypeStringType of insurance transaction, such as NewBusiness, Renewal, and Endorsement.

Outputs 

OutputDetails
contextIdType
String
Description
Context ID of the insurance quote.
pricingResultsType
Map<String, Object>
Description
Recalculated pricing details of the insurance product.
productRatingOutputType
Apex-defined
Description
An Apex ConnectApi__ProductRatingOutputRepresentation record that contains the product rating details.

Example 

Sample Request

1{
2  "inputs": [
3    {
4      "effectiveDate": "2024-10-18",
5      "ratingInputs": "[{\"instanceKeys\":[\"AutoRoot\",\"AutoBundle\",\"NewDriver\"],\"productCode\":\"autoDriver\",\"attributes\":{\"DriverAccidents\":4},\"targetRecords\":[\"003xx000004WhKhAAK\"]}]",
6      "ratingOptions": {
7        "returnRatingResults": true,
8        "returnContextJson": true,
9        "returnProductDetails": true
10      }
11    }
12  ]
13}

This is a sample request to call this invocable action from Apex code.

1// Sample Apex call for createInsuranceRating invocable action
2public class CreateInsuranceRatingInvoke {
3    private static final String ACTION_NAME = 'createInsuranceRating';
4
5    public static Boolean invokeMethod(
6        Map<String, Object> inputs,
7        Map<String, Object> output,
8        Map<String, Object> options
9    ) {
10        Map<String, Object> postPayload = (Map<String, Object>) getValueFromMap('postPayload', inputs, options);
11        System.debug('Rating post Input: ' + postPayload);
12
13        if (postPayload == null) {
14            output.put('success', false);
15            output.put('errorMessage', 'postPayload is required for rating patch');
16            output.put('errorType', 'VALIDATION_ERROR');
17            return false;
18        }
19
20        try {
21            System.debug('Calling Invocable Action: createInsuranceRating');
22
23            Invocable.Action action = Invocable.Action.createStandardAction(ACTION_NAME);
24
25            System.debug('RatingInputs: ' + postPayload.get('ratingInputs'));
26            setInvocationParameter(action, postPayload, 'ratingInputs', true);
27
28            action.setInvocationParameter('transactionType', postPayload.get('transactionType'));
29
30            setInvocationParameter(action, postPayload, 'additionalFields', true);
31
32            action.setInvocationParameter('effectiveDate', postPayload.get('effectiveDate'));
33
34            if (postPayload.containsKey('ratingOptions')) {
35                System.debug('Options:' + postPayload.get('ratingOptions'));
36                Map<String, Object> ratingOptions = (Map<String, Object>) postPayload.get('ratingOptions');
37                action.setInvocationParameter('ratingOptions', ratingOptions);
38            }
39
40            List<Invocable.Action.Result> results = action.invoke();
41
42            if (results != null && !results.isEmpty()) {
43                Invocable.Action.Result result = results[0];
44
45                if (result.isSuccess()) {
46                    System.debug('Rating post successfully via Invocable Action');
47                    output.put('ratingData', result.getOutputParameters());
48
49                    List<Invocable.Action.Error> actionErrors = result.getErrors();
50                    if (actionErrors != null && !actionErrors.isEmpty()) {
51                        output.put('success', false);
52                        output.put('error', result.getErrors());
53                        return false;
54                    }
55                    output.put('success', true);
56                    return true;
57
58                } else {
59                    List<Invocable.Action.Error> actionErrors = result.getErrors();
60                    String errorMessage = 'Rating post Invocable Action failed';
61
62                    if (actionErrors != null && !actionErrors.isEmpty()) {
63                        List<String> errorMessages = new List<String>();
64                        List<Map<String, Object>> errorDetailsList = new List<Map<String, Object>>();
65
66                        for (Invocable.Action.Error actionError : actionErrors) {
67                            errorMessages.add(actionError.getMessage());
68                            errorDetailsList.add(new Map<String, Object>{
69                                'message' => actionError.getMessage(),
70                                'code' => actionError.getCode()
71                            });
72                        }
73
74                        errorMessage = String.join(errorMessages, '; ');
75                        output.put('actionErrors', errorDetailsList);
76                    }
77
78                    output.put('success', false);
79                    output.put('errorMessage', errorMessage);
80
81                    System.debug(LoggingLevel.ERROR, 'Rating post Invocable Action failed: ' + errorMessage);
82                    return false;
83                }
84
85            } else {
86                output.put('success', false);
87                output.put('errorMessage', 'Rating post Invocable Action returned null or empty results');
88                System.debug(LoggingLevel.WARN, 'Rating post Invocable Action returned null/empty results');
89                return false;
90            }
91
92        } catch (Exception e) {
93            String errorMsg = 'Exception: ' + e.getMessage();
94            output.put('success', false);
95            output.put('errorMessage', errorMsg);
96            output.put('errorType', 'EXCEPTION');
97            System.debug(LoggingLevel.ERROR, 'Exception while rating post: ' + errorMsg);
98            return false;
99        }
100    }
101
102    private static Object getValueFromMap(String key, Map<String, Object> inputs, Map<String, Object> options) {
103        if (inputs != null && inputs.get(key) != null && String.isNotBlank(String.valueOf(inputs.get(key)))) {
104            return inputs.get(key);
105        }
106        else if (options != null && options.get(key) != null && String.isNotBlank(String.valueOf(options.get(key)))) {
107            return options.get(key);
108        }
109
110        return null;
111    }
112
113    private static void setInvocationParameter(
114        Invocable.Action action,
115        Map<String, Object> payload,
116        String inputAttribute,
117        Boolean serializeJSON
118    ) {
119        if (payload.containsKey(inputAttribute) && payload.get(inputAttribute) != null) {
120            System.debug(inputAttribute + ': ' + JSON.serialize(payload.get(inputAttribute)));
121            if (serializeJSON) {
122                action.setInvocationParameter(inputAttribute, JSON.serialize(payload.get(inputAttribute)));
123            } else {
124                action.setInvocationParameter(inputAttribute, payload.get(inputAttribute));
125            }
126        } else {
127            System.debug('payload does not contain attribute: ' + inputAttribute);
128        }
129    }
130}

Sample Response

1[
2  {
3    "actionName": "repriceInsuranceProduct",
4    "errors": null,
5    "invocationId": null,
6    "isSuccess": true,
7    "outcome": null,
8    "outputValues": {
9      "contextId": "273e01fdfb6f9f21428869eb784ee756976afb0e9bdc49f2a360be397a10ca12",
10      "productRatingOutput": {
11        "ratingResult": {
12          "childNodes": [
13            {
14              "childNodes": [
15                {
16                  "childNodes": [
17                    {
18                      "childNodes": [],
19                      "details": {
20                        "NetUnitPrice": null,
21                        "InstanceKey": "Driver",
22                        "ProductCode": "driver",
23                        "NetTotalPrice": 0,
24                        "Driver_Accident_Points": 15,
25                        "ProratedQLITaxAmount": 0,
26                        "Driver_MVR_Points": 8,
27                        "Age_First_Licensed": 16
28                      }
29                    },
30                    {
31                      "childNodes": [],
32                      "details": {
33                        "NetUnitPrice": 501.84,
34                        "InstanceKey": "Comprehensive",
35                        "ProductCode": "comprehensive",
36                        "NetTotalPrice": 501.84,
37                        "ProratedQLITaxAmount": 0
38                      }
39                    }
40                  ],
41                  "details": {
42                    "NetUnitPrice": 501.84,
43                    "InstanceKey": "Auto1",
44                    "ProductCode": "auto",
45                    "NetTotalPrice": 501.84,
46                    "ProratedQLITaxAmount": 0
47                  }
48                }
49              ],
50              "details": {
51                "NetUnitPrice": 1485.84,
52                "InstanceKey": "AutoSilver",
53                "ProductCode": "autoSilver",
54                "NetTotalPrice": 1485.84,
55                "ProratedQLITaxAmount": 0
56              }
57            }
58          ],
59          "details": {}
60        },
61        "productDetails": [
62          {
63            "productSpecificationType": {
64              "productSpecificationRecordType": {},
65              "name": "InsuredParty"
66            },
67            "childProducts": [],
68            "additionalFields": {
69              "ProductCode": "driver",
70              "SpecificationType": "InsuredParty",
71              "BasedOnId": "11Bxx000002C1kZEAS",
72              "Name": "Driver"
73            },
74            "availabilityDate": null,
75            "description": null,
76            "productInformation": null,
77            "childVariationIds": [],
78            "isActive": true,
79            "qualificationContext": null,
80            "productClassification": {
81              "id": "11Bxx000002C1kZEAS"
82            },
83            "productComponentGroups": [],
84            "configureDuringSale": "Allowed",
85            "productRelatedComponent": null,
86            "id": "01txx0000006i3iAAA",
87            "prices": [],
88            "isComponentRequired": null,
89            "productType": null,
90            "isAssetizable": true,
91            "isSoldOnlyWithOtherProds": false,
92            "attributeCategories": [
93              {
94                "code": "Driving History",
95                "records": [
96                  {
97                    "isRequired": false,
98                    "code": "AgeFirstLicensed",
99                    "additionalFields": {},
100                    "attributeCategoryId": "0v3xx0000000001AAA",
101                    "hidden": false,
102                    "isConfigurable": false,
103                    "dataType": "NUMBER",
104                    "label": "Age First Licensed",
105                    "isReadOnly": false,
106                    "isCloneable": false,
107                    "name": "Age First Licensed",
108                    "id": "0tjxx000000001FAAQ",
109                    "attributeNameOverride": "Age First Licensed",
110                    "isPriceImpacting": true,
111                    "developerName": "Age_First_Licensed",
112                    "status": "Active"
113                  }
114                ],
115                "name": "Driving History"
116              }
117            ],
118            "nodeType": "simpleProduct",
119            "displayUrl": null,
120            "productSellingModelOptions": [
121              {
122                "productSellingModel": {
123                  "sellingModelType": "OneTime",
124                  "name": "One Time",
125                  "id": "0jPxx0000000001EAA",
126                  "doesAutoRenewByDefault": false,
127                  "status": "Active"
128                },
129                "productSellingModelId": "0jPxx0000000001EAA",
130                "isDefault": true,
131                "productId": "01txx0000006i3iAAA",
132                "id": "0iOxx000000000zEAA"
133              }
134            ],
135            "productQuantity": null,
136            "productCode": "driver",
137            "name": "Driver"
138          }
139        ],
140        "contextJSON": {
141          "salesTransactions": [
142            {
143              "salesTransactionItems": [
144                {
145                  "salesTransactionItemClauses": [],
146                  "childNodes": [
147                    {
148                      "salesTransactionItemClauses": [],
149                      "childNodes": [],
150                      "salesTransactionItemAttributes": [
151                        {
152                          "fields": {
153                            "AttributeKey": "0tjxx000000000PAAQ",
154                            "AttributeValue": "50",
155                            "ParentReference": "ref_681c203e_5491_4d5f_a296_02a0b3dfa181",
156                            "hasObjectRef": null,
157                            "AttributePicklistValue": "0v6xx000000000ZAAQ",
158                            "IsPriceImpacting": false,
159                            "businessObjectType": "QuoteLineItemAttribute",
160                            "AttributeName": "Deductible",
161                            "AttributeDefinitionCode": "Deductible",
162                            "id": "ref_fdd78e30_1258_4ea3_9f56_c74245ae58d6",
163                            "SalesTransactionItemAttrParent": "ref_681c203e_5491_4d5f_a296_02a0b3dfa181",
164                            "AttributeDeveloperName": "Deductible"
165                          }
166                        }
167                      ]
168                    }
169                  ],
170                  "salesTransactionItemRelatedObjects": [],
171                  "salesTransactionItemTaxes": [],
172                  "fields": {
173                    "LevelTwoBasePremium": 120,
174                    "IntermediateVariableTwo": null,
175                    "Product": "01txx0000006i3UAAQ",
176                    "businessObjectType": "QuoteLineItem",
177                    "DYN__License_State": null,
178                    "RevenueCloudPackagingFlag": "C",
179                    "ValidationResult": null,
180                    "DYN__AssetRecordName": null,
181                    "PolicyPremium": 1485.84,
182                    "PeriodBoundaryStartMonth": null,
183                    "SalesTransactionSourceAsset": null,
184                    "ProratedQLITaxAmount": 0,
185                    "id": "ref_681c203e_5491_4d5f_a296_02a0b3dfa181",
186                    "TaxTreatment": null,
187                    "Subtotal": null,
188                    "LineItemPath": "ref_e112c127_367c_41c8_a5ce_1d7e69ac58bc/ref_681c203e_5491_4d5f_a296_02a0b3dfa181",
189                    "DiscountAmount": null,
190                    "PricebookEntry": null,
191                    "NetUnitPrice": 590.4,
192                    "ParentSalesTransactionItem": "ref_e112c127_367c_41c8_a5ce_1d7e69ac58bc",
193                    "ObligatedAmount": null,
194                    "DYN__Age_First_Licensed": null,
195                    "LevelThreePremium": null,
196                    "ProductName": "Bodily Injury &amp; Property Damage",
197                    "ProformaBillingPeriodAmount": null,
198                    "CommissionAmount": null,
199                    "ProductSpec": "Coverage",
200                    "DYN__Last_Name": null,
201                    "PricingTermCount": null,
202                    "DYN__ContactRecordName": null,
203                    "RoundedLineAmount": null,
204                    "SalesTransactionAction": null,
205                    "TransactionType": null,
206                    "PricingTermUnit": null,
207                    "BasisTransactionItem": null,
208                    "PricingSource": null,
209                    "StockKeepingUnit": null,
210                    "DYN__Year": null,
211                    "PartnerUnitPrice": null,
212                    "ItemTotalAdjustmentAmount": null,
213                    "ArePartialPeriodsAllowed": false,
214                    "DYN__Bodily_Injury_Per_Person_Limit": 1000,
215                    "DYN__Colour": null,
216                    "FactorP": null,
217                    "FactorO": null,
218                    "CustomProductName": null,
219                    "SalesTransactionItemParent": "ref_ed3d9643_12e4_4709_9f74_69c8292d65b4",
220                    "Quantity": 1,
221                    "ContractId": null,
222                    "ItemGroupSummarySubtotal": null,
223                    "DYN__AccountRecordName": null,
224                    "DYN__E_Mail": null,
225                    "DYN__First_Name": null,
226                    "DYN__Bodily_Injury_Per_Accident_Limit": 1000,
227                    "DYN__Driver_Accident_Points": null,
228                    "SalesItemType": null,
229                    "ItemPath": "01txx0000006i3DAAQ/01txx0000006i3UAAQ"
230                  },
231                  "salesTransactionItemRelationships": [
232                    {
233                      "fields": {
234                        "ParentReference": "ref_681c203e_5491_4d5f_a296_02a0b3dfa181",
235                        "AssociatedItem": "ref_681c203e_5491_4d5f_a296_02a0b3dfa181",
236                        "MainItemRole": null,
237                        "ProductRelatedComponent": "0dSxx000000000XEAQ",
238                        "businessObjectType": "QuoteLineRelationship",
239                        "AssociatedItemPricing": "IncludedInBundlePrice",
240                        "ProductRelationshipType": "0yoxx0000000001AAA",
241                        "RootItemProductCode": "autoSilver",
242                        "IsPriceInclusive": true,
243                        "RootItem": "ref_e112c127_367c_41c8_a5ce_1d7e69ac58bc",
244                        "RootItemProductSellingModel": null,
245                        "AssociatedQuantScaleMethod": null,
246                        "MainItem": "ref_e112c127_367c_41c8_a5ce_1d7e69ac58bc",
247                        "AssociatedItemRole": null,
248                        "SalesTrnItemRelationshipParent": null,
249                        "id": "ref_80623cb4_3abd_4ee0_876a_c5ca9ecc07fc",
250                        "MainItemProduct": "01txx0000006i3DAAQ",
251                        "MainItemProductSellingModel": null,
252                        "RootItemProduct": "01txx0000006i3DAAQ"
253                      }
254                    }
255                  ]
256                }
257              ],
258              "salesTransactionItemAttributes": [],
259              "salesTransactionItemRelatedObjects": [],
260              "salesTransactionItemTaxes": [],
261              "fields": {
262                "LevelTwoBasePremium": null,
263                "IntermediateVariableTwo": null,
264                "Product": "01txx0000006i3DAAQ",
265                "businessObjectType": "QuoteLineItem",
266                "DYN__License_State": null,
267                "RevenueCloudPackagingFlag": "C",
268                "ValidationResult": null,
269                "DYN__AssetRecordName": null,
270                "PolicyPremium": 1485.84,
271                "PeriodBoundaryStartMonth": null,
272                "SalesTransactionSourceAsset": null,
273                "ProratedQLITaxAmount": 0,
274                "id": "ref_e112c127_367c_41c8_a5ce_1d7e69ac58bc",
275                "DYN__Age": null,
276                "DYN__Property_Damage_Per_Accident_Limit": null,
277                "DYN__Deductible": null,
278                "STICurrencyIsoCode__std": null,
279                "IntermediateVariableOne": null,
280                "BillingFrequency": null,
281                "DYN__State": null,
282                "DYN__DOB": null,
283                "ProductCode": "autoSilver",
284                "DerivedPricingAttribute": false,
285                "ItemPath": "01txx0000006i3DAAQ"
286              },
287              "salesTransactionItemRelationships": []
288            }
289          ],
290          "fields": {
291            "Account": null,
292            "BillingCity": null,
293            "businessObjectType": "Quote",
294            "SalesTransactionName": null,
295            "StatusCode": null,
296            "ProratedAmount": 1485.84,
297            "StartDate": "2025-11-04",
298            "CurrencyIsoCode__std": null,
299            "BillingPostalCode": null,
300            "id": "ref_ed3d9643_12e4_4709_9f74_69c8292d65b4",
301            "BillingState": null,
302            "CensusRatingType__std": null,
303            "TransactionType": "AutoTransactionType",
304            "UserProfile": "System Administrator",
305            "QuoteAccount": null,
306            "TotalProratedAmount": 1485.84,
307            "CensusType__std": null,
308            "GroupCensus": null,
309            "SalesTransactionType": null,
310            "Pricebook": null,
311            "Opportunity": null,
312            "ShippingCountry": null,
313            "ShippingCity": null,
314            "StandardAmount": 1485.84,
315            "ProratedTaxAmount": 0,
316            "RatingDate": null,
317            "SalesTransactionSource": "ref_ed3d9643_12e4_4709_9f74_69c8292d65b4",
318            "EffectiveDate": "2025-11-04T00:00:00.000Z",
319            "TotalStandardAmount": 1485.84
320          },
321          "appUsageAssignments": []
322        }
323      }
324    },
325    "sortOrder": -1,
326    "version": 1
327  }
328]