function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sumant KuchipudiSumant Kuchipudi 

Upsert Account failing with Duplicate error

I have created an external field in Account and have very simple code that upserts Account record.
below is the code
Account a = new Account();
a.name='Testing 99test9911';
a.Account_External_Id__c='99test99';
upsert a;
First time it creatd record but next time when I ran it failed (below is error), my environment is pretty much new (no triggers and no Workflows and no ProcessBuilders), I don't know how to fix this. Please advice
12:11:45:057 EXCEPTION_THROWN [4]|System.DmlException: Upsert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: Account_External_Id__c duplicates value on record with id: 0010t0000137DHM: []

 
Sumant KuchipudiSumant Kuchipudi
I found the issue, need to use Account_External_Id__c in the upsert line ..
Account a = new Account();
a.name='Testing 99test9911';
a.Account_External_Id__c='99test99';
upsert a Account_External_Id__c;
Thanks