You need to sign in to do that
Don't have an account?
DUPLICATE_VALUE, duplicate value found
Hi,
I have a strange situation here.
I have written a web service class which searches for MemberID (which is unique) in Accounts, if its found then it updates that record OR else it inserts new record. The values for each fields in Accounts are supplied as a XML string parameter from Java. So the Java program calls this web service methods by passing XML strings.
All works well when tested with some static inputs, however when this method called in bulk, I get he error -
Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: Member_ID__c duplicates value on record with id: 0019000000CZC83: []
I have no clue why and how could this happen? As I am searching for Member_ID__c in my query then inserting if its not found. As an additional step, I replaced 'insert' by 'upsert', still I am getting this exception.
Can you post your WS method there are 2 posibilities
1.)Recursive call
2.)Redudant update in some trigger/workflow
if u upserting data based on MemberID then make it as external Id & try below
Upsert ObjectName MemberID;
I hope its solve ur problem
Thanks Abhay Arora and SFDevelopers for your reply.
Here is the web service code snippet:
In the insertAccount() method I am actually upserting Account. So here I am getting exception, and that is caught in Catch{} block.
Any suggestion??
Member_ID__c is external ID. I will try Upsert Object MemberID; now.
Hi Abhay, I have posted the WS code snippet. Even I thought of recursive call or same Member ID being inserted in separate threads, hence the exception. But not too sure whether such multi-thread thing can happen.
Basically its not just Account, there is Opportunity also (called as Policy here). So an Account can have multiple Policies. Hence the different XML can contain details of same Member (or Account) in its tags. In each thread, if the SFDC takes different XML, first it will search for Member_ID__c if its not found then it will insert, the second thread simultaneously does this (finds no matching Member_ID - since the other thread still might be executing), and hence this DUPLICATE_FOUND exception. If mu line of thinking is wrong, let me know.
Thanks again.
What is initial value of responseCode? Below seems to be the problem just add a check for null befor enterig into if/else part that should solve your problem
OR just add a initial value to responseCode say 'NotSet' and check this also along with other conditions that also may work for you
Hi abhi_the1,
The reason you get this error message is because your request is dealt with in bulk.
So lets say your incoming xml has the follwing memberIds:
memberId1
memberId2
memberId4
memberId5
memberId1 <- this is a repeat id
memberId3
memberId2 <- this is repeated as well
Now, you when insert or upsert in bulk, salesforce will try to perform this operation in bulk. This means when it tries insert the values, it tries to create 2 records with the same member id (ie. 1 and 2). This is why you get the error message.
The key to resolve this would be to parse the data from the xml, and create a unique set of member Id records that you want insert or update before calling insert of update.
Hope this makes sense!
- Anup
Abhay, the initial value is set to ''. I dont have any problem if I try with static or hard coded XML values. Everything works absolutely fine.
Anup, yes this might be the case, as XML is dynamically being generated in bulk. Now the challenge is to put everything in unique set. But here, it will create/insert new records only if it doesn't exist (checked in checkForAccount() method). I am not able give any explanation to myself.
Thanks for the suggestion guys. Appreciate it a lot.
Hey Abhi,
So in order to get unique ids from list you can
1.) iterate over the list get ids in a set
2.) iterate over the SET and get a new list with only unique data
Now send this unique data to the system to process them using checked in checkForAccount()
If any of the records are duplicate flag them in a way and insert remaining and end of the process just email the remaining(duplicate records )
For above you can use some kind of wrapper class in which you can hold the flagged data
Adding for purposes of documentation:
In my case, I've encountered this error when upserting records in bulk and a record update failed because of permissions limitations.