You need to sign in to do that
Don't have an account?
Dheeraj shokeen
How to insert the duplicate record is any way to insert the duplicate record using Apex
Status Code : 500
Error Response : [{"errorCode":"APEX_ERROR","message":"System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATES_DETECTED, You're creating a duplicate Lead record. We recommend you use an existing record instead.: []\n\nClass.LeadReceiver.doPost: line 13, column 1"}]
Error Response : [{"errorCode":"APEX_ERROR","message":"System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATES_DETECTED, You're creating a duplicate Lead record. We recommend you use an existing record instead.: []\n\nClass.LeadReceiver.doPost: line 13, column 1"}]
By setting the allOrNone parameter of the Database.insert() method to false, you allow the insertion of the duplicate record. However, this bypasses the duplicate rules entirely and it is generally not recommended to insert duplicate records as it can lead to data inconsistencies and other issues.
Example code
This would give output as Error message: Use one of these records? which implies the duplicate rule is active and is preventing the creation of duplicates. In such cases, you may need to either update the existing record or modify the duplicate rule (You may check this in Salesforce under Setup > Data Management > Duplicate Management > Duplicate Rules) to allow the insertion of duplicates if that aligns with your business requirements.
Related: https://help.salesforce.com/s/articleView?id=sf.duplicate_rules_standard_lead_rule.htm&type=5
https://help.formassembly.com/help/salesforce-error-use-one-of-these-records
If this information helps, please mark the answer as best. Thank you
Database.DMLOptions dmlOptions = new Database.DMLOptions();
dmlOptions.duplicateRuleHeader.allowSave = true;
Database.insert(newlead, dmlOptions);