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
PowerUserPowerUser 

AutoNumber and Upsert!... This is DRIVING ME CRAZY! :)

I'm calling upsert on a custom object with a custom id field.  I set that id field to "AutoNumber" and also set it to be an external id.

 

When I call upsert, if the id passed in, matches an id in a previously added record, it updates great.  Updating works perfect.

 

Now, when I don't have an id, I pass null in the id field.  The upsert fails because it says it requires the id field.  I don't have an id for a new record.  Even when I do pass in an id, the upsert STILL fails, because is says I can't set a value myself to an AutoNumber field.

 

What I would expect is, if I pass in a matching id, it updates the record.  If I pass in a null id, it creates a new record with the AutoNumber having incremented.

 

What do I do?

 

Here is the code:

 

sforce.Time__c[] time = new Time__c[1];

time[0] = new sforce.Time__c();

Dictionary<string, Object> dataRow = (Dictionary<string, Object>)data[i];

time[0].id__c = dataEntry.Value;  // THIS MAY BE NULL, OR IT MAY BE AN ACTUAL NUMBER ID 

time[0].date__c = Convert.ToDateTime(dataEntry.Value);time[0].date__cSpecified =

true; time[0].time__c = (string)dataEntry.Value;

 

sforce.UpsertResult ur = binding.upsert("id__c", time)[0]; // THE id_c FIELD IS THE AUTONUMBER FIELD.

AlwaysConfusedAlwaysConfused

 

The whole point in an autonumber field is that you can't set it.

The system figures out the next free number and sets it for you.

 

that's probably where you're going wrong.