This is a discussion on upsert duplicate_value error within the Salesforce PHP Tutorials forums, part of the Salesforce category; Hey folks.. Total n00b to salesforce, working on a project for a
-
upsert duplicate_value error
Hey folks.. Total n00b to salesforce, working on a project for a client.
I'm cobbling together an app to get user info from several disparate databases into SF, and I'm running into an issue with my testing of the upsert method.
I'm able to upsert a single record as both an insert and then a subsequent update. But if I have the same value for a key in a group of records going into the upsert, the API chokes with a DUPLICATE_VALUE error.
Now, correct me if I'm wrong, but isn't that the whole point of the upsert? Do an insert if the record doesn't exist, otherwise update it if it does? Does anyone have a solution for this test case (I'm sure it's got to crop up in real life all the time, no?), or am I doing something completely wrong?
Here's basically what's happening:
1. select a bunch of results from local DB
2. map the local DB data to SF fields
3. push a given record set into a master array
4. loop through that array to create sObject instances, and push those instances onto a stack of sObjects (from the php upsert tutorial at Salesforce PHP Upsert Tutorial - developer.force.com)
5. fire off the upsert.
If you need the real actual PHP code, let me know and I'll post it.
In my test case, I've got 3 rows with differing data, but all have the same email address value. Doing print_r() on the results back from SF returns the following:
Code:
Array
(
[0] => stdClass Object
(
[created] =>
[errors] => stdClass Object
(
[fields] => Username__c
[message] => Duplicate external id specified: user@domain.com
[statusCode] => DUPLICATE_VALUE
)
[id] =>
[success] =>
)
[1] => stdClass Object
(
[created] =>
[errors] => stdClass Object
(
[fields] => Username__c
[message] => Duplicate external id specified: user@domain.com
[statusCode] => DUPLICATE_VALUE
)
[id] =>
[success] =>
)
[2] => stdClass Object
(
[created] =>
[errors] => stdClass Object
(
[fields] => Username__c
[message] => Duplicate external id specified: user@domain.com
[statusCode] => DUPLICATE_VALUE
)
[id] =>
[success] =>
)
)
Thanks!
-Rob
-
Rob sorry for the delay in responding to your post. I have been extremely busy at work. I will look at it within the next 24 hours and I will check it out and let you know if I can help you out.
-
Mike- Thanks.. Really just curious at t his point. I wound up re-jiggering what I've got happening at my end and syncing information prior to sending it over to SF, but if you have any input or comments on my post, I'd love to hear them (should I be using Contacts, or a custom object, etc?).
-Rob
-
So your external ID it set to your username__c field ? Maybe if you emailed me the code or if you do not mind posting it here I can take a look at it
Similar Threads
-
By monloi in forum Salesforce Coding Discussions
Replies: 2
Last Post: 02-18-2009, 07:26 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
Bookmarks