Account parentAccount = TestUtils.createAccountWithRecordType(Schema.SObjectType.Account.getRecordTypeInfosByName().get('Parent Account').getRecordTypeId(),false);
        parentAccount.City__c = 'Delhi';
        insert parentAccount;

Account childAccount = TestUtils.createAccountWithRecordType(Schema.SObjectType.Account.getRecordTypeInfosByName().get('Account').getRecordTypeId(),false);
        childAccount.ParentId = parentAccount.id;
        childAccount.City__c = 'Jaipur';
        **insert childAccount;** // Here Error is Comming

closed as off-topic by glls, Pranay Jaiswal, Himanshu, Sebastian Kessel, battery.cord Apr 5 at 13:23

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on problems in code you've written must describe the specific problem and include valid code to reproduce it. For help writing short, self-contained syntactically-valid examples, see: SSCCE.org" – glls, Pranay Jaiswal, Himanshu, Sebastian Kessel, battery.cord
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Do you have any field on Account that is marked as Unique ? – Vijay Ganji Apr 3 at 12:10
  • Is it only your code? Or are you adding twice childs or Parent, for example? – m Peixoto Apr 3 at 12:18

In this context that error suggests that both the parentAccount and the childAccount share the same value for some unique identifier. I wonder if you have an external ID configured and this is getting set the same in both cases?

  • Thank you, Yes it is working now – Sanjay Apr 3 at 12:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.