• PowerUser
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies

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.

I'm using C# to call the Salesforce API.  I have a custom object with many custom fields.  I instantiate my custom object, and set all of the fields, and then send an upsert command with that object.

 

Every field saves just fine...  EXCEPT THE FIELD WITH A DATETIME TYPE!!!  I don't get it.  It forces me to save a DateTime object to that field, but never saves it.

 

The upsert finishes with no errors.  And like I said before: Every field is saved EXCEPT the dateTime field.

 

What is the problem?

 

Here is the code:

 

for (int i = 0; i < data.Length; i++)
                {
                    sforce.Time__c[] time = new Time__c[1];
                    time[0] = new sforce.Time__c();

                    Dictionary<string, Object> dataRow = (Dictionary<string, Object>)data[i];
                    foreach (KeyValuePair<string, Object> dataEntry in dataRow)
                    {
                            time[0].id__c = Convert.ToString(dataEntry.Value);

 

 // HERE IS WHERE IS SET THE DATETIME.  IT GETS STORED HERE, BUT NEVER SAVED AFTER UPSERT

                            time[0].date__c = Convert.ToDateTime(dataEntry.Value);
                            time[0].time__c = (string)dataEntry.Value;
                    }

 

// THE UPSERT SAVES ALL OTHER FIELDS, BUT IGNORES THE DATETIME.  NO ERRORS ON UR

                    sforce.UpsertResult ur = binding.upsert("id__c", time)[0];

}

I'm using C# to call the Salesforce API.  I have a custom object with many custom fields.  I instantiate my custom object, and set all of the fields, and then send an upsert command with that object.

 

Every field saves just fine...  EXCEPT THE FIELD WITH A DATETIME TYPE!!!  I don't get it.  It forces me to save a DateTime object to that field, but never saves it.

 

The upsert finishes with no errors.  And like I said before: Every field is saved EXCEPT the dateTime field.

 

What is the problem?

 

Here is the code:

 

for (int i = 0; i < data.Length; i++)
                {
                    sforce.Time__c[] time = new Time__c[1];
                    time[0] = new sforce.Time__c();

                    Dictionary<string, Object> dataRow = (Dictionary<string, Object>)data[i];
                    foreach (KeyValuePair<string, Object> dataEntry in dataRow)
                    {
                            time[0].id__c = Convert.ToString(dataEntry.Value);

 

 // HERE IS WHERE IS SET THE DATETIME.  IT GETS STORED HERE, BUT NEVER SAVED AFTER UPSERT

                            time[0].date__c = Convert.ToDateTime(dataEntry.Value);
                            time[0].time__c = (string)dataEntry.Value;
                    }

 

// THE UPSERT SAVES ALL OTHER FIELDS, BUT IGNORES THE DATETIME.  NO ERRORS ON UR

                    sforce.UpsertResult ur = binding.upsert("id__c", time)[0];

}