---
schema_version: "1"
id: dc3427d7c5df165c84c8f94bce9284cbca3a34bdc79e09bc09ed2e17e9d3f1c9
title: Invoke Underwriting Rules Action
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/insurance_developer_guide/actions_obj_invoke_underwriting_rules.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.insurance_developer_guide.meta/insurance_developer_guide/actions_obj_invoke_underwriting_rules.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 8b599fe97f169372ea169b72327f419f8f2b7d99b4b9a4da44c2b39d3683bcdc
description: Invoke the underwriting rules for different insurance records during the run time.
---
# Invoke Underwriting Rules Action

Invoke the underwriting rules for different insurance records during the run time.

This action is available in API version 65.0 and later.

## Supported REST HTTP Methods

**URI**: /services/data/vXX.X/actions/standard/invokeUnderwritingRules

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

| Input | Type | Description |
| --- | --- | --- |
| invokeUnderwritingRuleInputRep | Apex-defined | Required. An Apex ConnectApi.InvokeUnderwritingRuleInputRep record that contains the details of the object records to which the underwriting rules must be applied. |

## Outputs

| Output | Type | Description |
| --- | --- | --- |
| invokeUnderwritingRuleOputRep | Apex-defined | An Apex ConnectApi.InvokeUnderwritingRuleOputRep record that contains the details of the object records to which the underwriting rules are applied. |

## Example

Sample Request

{
    "inputs": \[
        {
            "invokeUnderwritingRuleInputRep": {
                "objectId": "0Zkxx000000001qCAA",
                "toStage": "Open"
            }
        }
    \]
}

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

public class InsuranceUnderwritingRuleApexService implements Callable {
    
    private static final String METHOD\_INVOKE\_UW\_RULE = 'invokeUnderwritingRule';
    private static final String OUTPUT\_NAME = 'invokeUnderwritingRuleOputRep';
    
    /\*\*
     \* @description Implementation of Callable interface for OmniStudio
     \* @param action Method name to invoke
     \* @param args Map containing input, output, and options
     \* @return Object result of the method invocation
     \*/
    public Object call(String action, Map<String, Object> args) {
        System.debug('InsuranceQuoteApexService: call ' + action);
        Boolean response = false;
        Map<String, Object> input = (Map<String, Object>) args.get('input');
        Map<String, Object> output = (Map<String, Object>) args.get('output');
        Map<String, Object> options = (Map<String, Object>) args.get('options');

         if (METHOD\_INVOKE\_UW\_RULE.equals(action)) {
             if (!input.containsKey('objectId') || input.get('objectId') == null) {
                 throw new IllegalArgumentException('objectId is missing or null');
             }
             if (!input.containsKey('toStage') || input.get('toStage') == null) {
                 throw new IllegalArgumentException('toStage is missing or null');
             }
             String objectId = (String)input.get('objectId');
             String toStage = (String)input.get('toStage');
             Object ruleResult = invokeUWRules(objectId, toStage);
             output.put('ruleResult', ruleResult);
             response = true;
         }
        return response;
    }     
    
    public static Object invokeUWRules(String objectId, String toStage) {
        System.debug('InsuranceUnderwritingRuleApexService: objectId:' +  objectId + ', toStage : ' + toStage);
 
            Object outputRep;
            
            try {
          
                
                System.debug('Calling Invocable Action: invokeUnderwritingRules');
            
                // Create and configure the invocable action
                Invocable.Action action = Invocable.Action.createStandardAction('invokeUnderwritingRules');
                
                // Set required invocation parameters
                ConnectApi.invokeUnderwritingRuleInputRep inputRep = new ConnectApi.invokeUnderwritingRuleInputRep();
                inputRep.objectId = objectId;
                inputRep.toStage = toStage;
                action.setInvocationParameter('invokeUnderwritingRuleInputRep', inputRep);
                
                // Execute the action
                List<Invocable.Action.Result> results = action.invoke();
                
                if (results != null && !results.isEmpty()) {
                    Invocable.Action.Result result = results\[0\];
                    
                    if (result.isSuccess()) {
                        System.debug('Invoke UW Rule successfully from Invocable Action'); 
                        // Extract key information from the result
                        Map<String, Object> outputParams = result.getOutputParameters();
                        if (outputParams != null) {
                            outputRep = outputParams.get(OUTPUT\_NAME);
                             System.debug('output: ' + JSON.serialize(outputRep));

                            return outputRep; 
                        }
                    } else {
                         System.debug('invoke UW Rule fail: ' + result);
                         return result.getErrors();
                    }
                }
                
            } catch (Exception e) {
                throw e;
            }
        return outputRep;
    }
}

Sample Response

\[
  {
    "actionName": "invokeUnderwritingRules",
    "errors": null,
    "invocationId": null,
    "isSuccess": true,
    "outcome": null,
    "outputValues": {
      "invokeUnderwritingRuleOputRep": {
        "objectId": "0Zkxx000000001qCAA",
        "objectName": "Claim",
        "fromStage": "Draft",
        "toStage": "Open",
        "stageTransitionName": "Draft to Open",
        "stageTransitionUnderwritingEvaluationId": "1Mjxx00000004C0CA2",
        "isSuccess": true,
        "rulesetResults": \[
          {
            "productId": "01tSM000005OFyGYAW",
            "evaluationCriteria": "1 OR 2",
            "isSuccess": true,
            "ruleResults": \[
              {
                "ruleApiName": "CollisionRule",
                "isSuccess": true
              },
              {
                "ruleApiName": "AutoSilverRule",
                "isSuccess": true
              }
            \]
          },
          {
            "productId": "01tSM000005OFyJYAW",
            "evaluationCriteria": "1",
            "isSuccess": true,
            "ruleResults": \[
              {
                "ruleApiName": "MedicalRule1",
                "isSuccess": true
              }
            \]
          }
        \]
      }
    },
    "sortOrder": -1,
    "version": 1
  }
\]