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
tymtym 

Problem with creating records in custom objects

I have been trying to add records to custom objects I have created, but am having a few problems as it doesn't seem to correctly add them (ie. the dates aren't correct - it just sets the record date to a generic 1/1/0001 12:00:00 AM, and is similar to what happens with doubles, setting every value uploaded to 0)... this is an example of my code (C#)... could anyone tell me if I am doing something wrong?

  // Update Salesforce
  void Update(Object Src, EventArgs E) {
    Km__c km = new Km__c();
  
    km.Dossier__c         = dossier1.Text;
    km.Km_Reading__c      = reading1.Text;
    km.Km_Reading_Date__c = Convert.ToDateTime(date1.Text);
  }

Dossier = Text; Reading = Text, Reading_Date = Date.

Thanks in advance,

Tym.

DevAngelDevAngel

Hi tym,

You need to set another field related to the date field.  This is a field generated by .Net, not required by our web service.  The field to set is Km_Reading_Date__cSpecified, I believe.  What you are doing by setting this to true, is that you are explicitly telling .Net that the value contained in Km_Reading_Date__c is one that you have set.  If you create a DateTime type variable, it will contain a value by default.  Due to this behavior, .Net does not know if the value was set by you and needs to be serialized into the SOAP request.  The serializer serializes all fields that are not null.  Because a DateTime field cannot be set to null, .Net uses this mechanaism to assure only the items that you want serialized will be.

 

Cheers