Newer Version Available
CreateClaim(CreateClaimInput)
Create a claim record.
API Version
65.0
Requires Chatter
No
Signature
public static ConnectApi.CreateClaimOutputRepresentation CreateClaim(ConnectApi.ClaimInputRepresentation CreateClaimInput)
Parameters
- CreateClaimInput
- Type: ConnectApi.ClaimInputRepresentation
- Details to create a claim.
Return Value
Example
Use this Apex example to create a new insurance claim by using the Create Claim API. This example shows how to create a ClaimInputRepresentation with claim details, participants, and items, and then invoke the Connect API method ConnectApi.ClaimFamily.CreateClaim() to submit the claim.
- Class Definition
- This Apex sample shows how to use the Create Claim API from the Connect API namespace to create an insurance claim record. The example includes building nested input structures for claim details, participants, claim items, and related objects.
-
1 2public with sharing class CreateClaimCallable 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 == 'createClaim') { 11 // Retrieve the claim input data from the input map 12 ConnectApi.ClaimInputRepresentation claimInput = (ConnectApi.ClaimInputRepresentation) inputMap.get('claimInput'); 13 System.debug('Start of connect API call to create claim'); 14 15 // Initialize the claim output representation 16 ConnectApi.CreateClaimOutputRepresentation claimData; 17 18 // Call the Connect API to create the claim 19 try { 20 claimData = ConnectApi.ClaimFamily.createClaim(claimInput); 21 System.debug('Claim created successfully: ' + claimData); 22 23 // Put the claim data in the output map 24 outputMap.put('claimData', claimData); 25 } 26 catch (Exception e) { 27 System.debug('Error while creating claim: ' + e.getMessage()); 28 outputMap.put('error', e.getMessage()); 29 } 30 31 // Return the claim data 32 return claimData; 33 } 34 35 // If the action is not recognized, return null 36 return null; 37 } 38} - Usage Example
- Use the CreateClaimCallable class to invoke the createClaim action and submit a new claim.
-
1CreateClaimCallable callable = new CreateClaimCallable(); 2 3// Prepare the input arguments 4Map<String, Object> input = new Map<String, Object>(); 5 6// Create and populate the ClaimInputRepresentation object 7ConnectApi.ClaimInputRepresentation claimInput = new ConnectApi.ClaimInputRepresentation(); 8 9// Set basic claim fields 10claimInput.name = 'Claim-Demo-Test-apex-1'; 11claimInput.claimType = 'Auto'; 12claimInput.lossDate = DateTime.now(); 13claimInput.productCode = 'AutoClaimRoot'; 14claimInput.claimReasonType = 'Accident'; 15claimInput.claimReason= 'Damage'; 16claimInput.lossType = 'Partial Loss'; 17claimInput.insurancePolicyId = '0YTxx000000000iGAA'; 18claimInput.accountId = '001xx000003GYiEAAW'; 19 20// Set additional fields 21Map<String, Object> additionalFields = new Map<String, Object>(); 22additionalFields.put('Severity', 'High'); 23claimInput.additionalFields = additionalFields; 24 25// Set claim items 26List<ConnectApi.ClaimItemInputRepresentation> itemList = new List<ConnectApi.ClaimItemInputRepresentation>(); 27 28// Create first item 29ConnectApi.ClaimItemInputRepresentation item1 = new ConnectApi.ClaimItemInputRepresentation(); 30item1.name = 'item1'; 31item1.category = 'Involved Injury'; 32item1.productCode = 'InvolvedInjury'; 33item1.instanceKey = 'item1'; 34item1.insuredItemId = '0YWxx00000000NbGAI'; 35item1.insurancePolicyCoverageId = '0cYxx0000000125EAA'; 36item1.participantInstanceKey = 'par1'; 37 38// Set item attributes 39List<ConnectApi.ClaimAttributeInputRepresentation> item1AttrList = new List<ConnectApi.ClaimAttributeInputRepresentation>(); 40 41ConnectApi.ClaimAttributeInputRepresentation genderAttr = new ConnectApi.ClaimAttributeInputRepresentation(); 42genderAttr.apiName = 'Gender'; 43genderAttr.value = 'Female'; 44item1AttrList.add(genderAttr); 45 46item1.attributes = item1AttrList; 47 48// Set item additional fields 49Map<String, Object> item1AdditionalFields = new Map<String, Object>(); 50 item1AdditionalFields.put('Description', 'test'); 51item1.additionalFields = item1AdditionalFields; 52 53// Set item related objects 54List<ConnectApi.ClaimRelatedObjectInputRepresentation> relatedObjList = new List<ConnectApi.ClaimRelatedObjectInputRepresentation>(); 55 56ConnectApi.ClaimRelatedObjectInputRepresentation accountRel = new ConnectApi.ClaimRelatedObjectInputRepresentation(); 57accountRel.recordId = '001xx000003GYiBAAW'; 58accountRel.recordObjName = 'Account'; 59relatedObjList.add(accountRel); 60 61item1.relatedObjects = relatedObjList; 62 63itemList.add(item1); 64claimInput.items = itemList; 65 66// Set claim participants 67List<ConnectApi.ClaimParticipantInputRepresentation> participantList = new List<ConnectApi.ClaimParticipantInputRepresentation>(); 68 69// Create first participant 70ConnectApi.ClaimParticipantInputRepresentation participant1 = new ConnectApi.ClaimParticipantInputRepresentation(); 71participant1.instanceKey = 'par1'; 72participant1.accountId = '001xx000003GYiEAAW'; 73participant1.contactId = '003xx000004WhFwAAK'; 74participant1.insurancePolicyParticipantId = '0aoxx00000000SQAAY'; 75participant1.isInjured = 'true'; 76participant1.roles = new List<String>{'Claimant', 'Involved Driver'}; 77 78participantList.add(participant1); 79 80// Create second participant 81ConnectApi.ClaimParticipantInputRepresentation participant2 = new ConnectApi.ClaimParticipantInputRepresentation(); 82participant2.instanceKey = 'par2'; 83participant2.contactId = '003xx000004WhFwAAK'; 84participant2.isInjured = 'true'; 85participant2.roles = new List<String>{'Claimant', 'Involved Driver'}; 86 87participantList.add(participant2); 88claimInput.participants = participantList; 89 90 91// Add the claimInput to the input map 92input.put('claimInput', claimInput); 93 94// Prepare the output map 95Map<String, Object> output = new Map<String, Object>(); 96 97// Prepare the args map 98Map<String, Object> args = new Map<String, Object>(); 99args.put('input', input); 100args.put('output', output); 101 102// Call the 'createClaim' action 103Object result = callable.call('createClaim', args); 104 105// Retrieve the claim data from the result 106ConnectApi.CreateClaimOutputRepresentation claimData = (ConnectApi.CreateClaimOutputRepresentation) result; 107 108// Output the claim data to the debug log 109System.debug('Claim Data: ' + JSON.serializePretty(claimData)); 110 111// Check for errors in the output map 112if (output.containsKey('error')) { 113 System.debug('Error: ' + output.get('error')); 114}