0

I have one requirement like if InsurancePolicy record with Policy_External_Id__c is already in salesforce then it should update that one else insert so for this I used Patch method below was my request body

{ "compositeRequest": [ { "method": "PATCH", "url": "/services/data/v50.0/sobjects/InsurancePolicy/Policy_External_Id__c/test-ID3124", "referenceId": "newPolicy", "body": { "Primary_Traveler_FirstName__c": "zy", "Primary_Traveler_LastName__c": "test", "Primary_Traveler_Birthdate__c": "1973-01-01", "ServicingOfficeStreet": "111 Main St", "ServicingOfficeCity": "surat", "ServicingOfficeState": "MA", "ServicingOfficePostalCode": "01002", "EffectiveDate": "2025-08-20", "ExpirationDate": "2025-10-20", "Name": "FIX203766", "Product": { "Product_External_Id__c": "Toi-F" }, "Email__c": "[email protected]", "Destination_Country__c": "USA", "Destination_State__c": "Arizona", "Phone__c": "123-456-789", "Airline_Account__r": { "Account_External_Id__c": "xyz-360" }, "Cruiseline_Account__c": null, "Tour_Operator_Account__c": null, "Customer_Care_Attribution__c": "ID3124", "NameInsured": { "Account_External_Id__c": "xyz-360" } } }, { "method": "POST", "url": "/services/data/v50.0/sobjects/Traveler__c", "referenceId": "traveler1", "body": { "First_Name__c": "xyy", "Last_Name__c": "test", "Birthdate__c": "1990-02-04", "Related_Policy__c": "@{newPolicy.id}" } }, { "method": "POST", "url": "/services/data/v50.0/sobjects/Traveler__c", "referenceId": "traveler2", "body": { "First_Name__c": "testing", "Last_Name__c": "name", "Birthdate__c": "2014-04-05", "Related_Policy__c": "@{newPolicy.id}" } }, { "method": "POST", "url": "/services/data/v50.0/sobjects/InsurancePolicyCoverage", "referenceId": "insuranceCoverage", "body": { "CoverageName": "Cancel", "LimitAmount": 1, "LimitPercentage": 2, "Description": "Testing coverage description", "PremiumAmount": 20, "InsurancePolicyId": "@{newPolicy.id}", "Code__c": "cancelForAnyReason" } } ] } 

below error i am getting as a response

{ "compositeResponse": [ { "body": [ "/services/data/v50.0/sobjects/InsurancePolicy/001Wr000006OBRQIA4", "/services/data/v50.0/sobjects/InsurancePolicy/001Wr000006KC3sIAG" ], "httpHeaders": {}, "httpStatusCode": 300, "referenceId": "newPolicy" }, { "body": [ { "errorCode": "PROCESSING_HALTED", "message": "Execution halted as previous operation (newPolicy) was not successful." } ], "httpHeaders": {}, "httpStatusCode": 400, "referenceId": "traveler1" }, { "body": [ { "errorCode": "PROCESSING_HALTED", "message": "Execution halted as previous operation (newPolicy) was not successful." } ], "httpHeaders": {}, "httpStatusCode": 400, "referenceId": "traveler2" }, { "body": [ { "errorCode": "PROCESSING_HALTED", "message": "Execution halted as previous operation (newPolicy) was not successful." } ], "httpHeaders": {}, "httpStatusCode": 400, "referenceId": "insuranceCoverage" } ] } 

can anyone help me to resolve this

1 Answer 1

0

The PATCH request for the InsurancePolicy is returning a 300 HTTP response code. This typically happens when the external ID you are using (Policy_External_Id__c) matches multiple records in Salesforce. The PATCH method expects a unique match for the external ID.

Make sure that the Policy_External_Id__c field is unique across all InsurancePolicy records. This can be enforced by setting the field as an external ID and unique in Salesforce.

If there is a possibility of multiple matches, you need to handle this scenario in your logic. You can first query for the records with the given external ID and then decide whether to update or insert based on the results.

Request Body as Below:

{ "compositeRequest": [ { "method": "GET", "url": "/services/data/v50.0/query/?q=SELECT+Id+FROM+InsurancePolicy+WHERE+Policy_External_Id__c='test-ID3124'", "referenceId": "checkPolicy" }, { "method": "PATCH", "url": "/services/data/v50.0/sobjects/InsurancePolicy/@{checkPolicy.records[0].Id}", "referenceId": "updatePolicy", "body": { "Primary_Traveler_FirstName__c": "zy", "Primary_Traveler_LastName__c": "test", "Primary_Traveler_Birthdate__c": "1973-01-01", "ServicingOfficeStreet": "111 Main St", "ServicingOfficeCity": "surat", "ServicingOfficeState": "MA", "ServicingOfficePostalCode": "01002", "EffectiveDate": "2025-08-20", "ExpirationDate": "2025-10-20", "Name": "FIX203766", "Product": { "Product_External_Id__c": "Toi-F" }, "Email__c": "[email protected]", "Destination_Country__c": "USA", "Destination_State__c": "Arizona", "Phone__c": "123-456-789", "Airline_Account__r": { "Account_External_Id__c": "xyz-360" }, "Cruiseline_Account__c": null, "Tour_Operator_Account__c": null, "Customer_Care_Attribution__c": "ID3124", "NameInsured": { "Account_External_Id__c": "xyz-360" } }, "ifUnmodifiedSince": "2023-01-01T00:00:00Z", "ifMatch": "*" }, { "method": "POST", "url": "/services/data/v50.0/sobjects/InsurancePolicy", "referenceId": "createPolicy", "body": { "Policy_External_Id__c": "test-ID3124", "Primary_Traveler_FirstName__c": "zy", "Primary_Traveler_LastName__c": "test", "Primary_Traveler_Birthdate__c": "1973-01-01", "ServicingOfficeStreet": "111 Main St", "ServicingOfficeCity": "surat", "ServicingOfficeState": "MA", "ServicingOfficePostalCode": "01002", "EffectiveDate": "2025-08-20", "ExpirationDate": "2025-10-20", "Name": "FIX203766", "Product": { "Product_External_Id__c": "Toi-F" }, "Email__c": "[email protected]", "Destination_Country__c": "USA", "Destination_State__c": "Arizona", "Phone__c": "123-456-789", "Airline_Account__r": { "Account_External_Id__c": "xyz-360" }, "Cruiseline_Account__c": null, "Tour_Operator_Account__c": null, "Customer_Care_Attribution__c": "ID3124", "NameInsured": { "Account_External_Id__c": "xyz-360" } }, "ifUnmodifiedSince": "2023-01-01T00:00:00Z", "ifMatch": "*" }, { "method": "POST", "url": "/services/data/v50.0/sobjects/Traveler__c", "referenceId": "traveler1", "body": { "First_Name__c": "xyy", "Last_Name__c": "test", "Birthdate__c": "1990-02-04", "Related_Policy__c": "@{updatePolicy.id}" } }, { "method": "POST", "url": "/services/data/v50.0/sobjects/Traveler__c", "referenceId": "traveler2", "body": { "First_Name__c": "testing", "Last_Name__c": "name", "Birthdate__c": "2014-04-05", "Related_Policy__c": "@{updatePolicy.id}" } }, { "method": "POST", "url": "/services/data/v50.0/sobjects/InsurancePolicyCoverage", "referenceId": "insuranceCoverage", "body": { "CoverageName": "Cancel", "LimitAmount": 1, "LimitPercentage": 2, "Description": "Testing coverage description", "PremiumAmount": 20, "InsurancePolicyId": "@{updatePolicy.id}", "Code__c": "cancelForAnyReason" } } ] } 
2
  • Hey Tushar Thanks for your response but what I found here is if there is no record for insurancepolicy then it's giving this 300 status code response otherwise if you have record in salesforce (any record) then its working fine. Commented Aug 9, 2024 at 9:05
  • As per the documentation, The 300 returned when an external ID exists in more than one record. The response body contains the list of matching records. Commented Aug 9, 2024 at 9:29

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.