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
MT DevMT Dev 

Rookie Problem: Contact.CreatedDate Disappears from Web Service Results

I'm using Visual Studio 2005 to attempt to create a web service that wraps the API so different applications (internal) can utilize Salesforce.com data. When I execute a web service that returns an array of Contact objects (using the enterprise wsdl), the CreatedDate dissapears from the results. However, right before I end the web service, I can see the created date while debugging. Here is a sample:

Code:
[WebMethod]
public SalesforceApi.AppExchangeService.Contact[] GetContacts(string fieldList, string criteria, string username, string passcode)
{
    SalesforceApi.BindingApi binding = new SalesforceApi.BindingApi(username, pwd);
    SalesforceApi.ContactApi contactApi = new SalesforceApi.ContactApi(binding);
    SalesforceApi.AppExchangeService.Contact[] contactList = contactApi.Query(fieldList, criteria);
    return contactList;
}
The result comes out without several fields. In particular, here is the results around CreatedDate:

Code:
<AssistantPhone xsi:nil="true" xmlns="urn:sobject.enterprise.soap.sforce.com" />
<CreatedById xsi:nil="true" xmlns="urn:sobject.enterprise.soap.sforce.com" />
<CurrencyIsoCode xsi:nil="true" xmlns="urn:sobject.enterprise.soap.sforce.com" />

Is there a special setting I need to have in place in order to retain the createdDate? I did notice that
CreatedDateFieldSpecified and CreatedDateSpecified are both false, but I wasn't sure that related
to a plan SOQL statement.

Thanks in advance.
SuperfellSuperfell
CreatedDate (and any other field) will only be populated if you include in the field list of the SOQL query.
Gareth DaviesGareth Davies

I take it that you are using enterprise WSDL.

This is from some code we developed in 2004:

Code:

static private sforce.SforceService binding;
Contact cont = new Contact();
ArrayList allContacts = new ArrayList();
QueryResult qr = null;
binding.QueryOptionsValue = new sforce.QueryOptions();
binding.QueryOptionsValue.batchSize = BatchSize;
binding.QueryOptionsValue.batchSizeSpecified = true;
try 

    
   {
    qr = binding.query(
     "select ID,FirstName,LastName,Phone,MobilePhone,Department,Description,CreatedDate from Contact where AccountId='" + (pAccount.Id).ToString() +"'"
     );
    if (qr.size > 0) 
    {
     howMany= qr.size > pNumberReturns — pNumberReturns : qr.size;

     for (counter =0; counter < howMany ; counter++) 
     {
      cont = ((Contact) qr.records[counter]);
      allContacts.Add(cont);
     
     }
    } 
    else 
    {
                                ///Handle Empty case
    }
    return (allContacts);
   } 
   catch (Exception ex) 
   {
    MessageBox.Show ("Query failed with message: " + ex.Message);
    return(allContacts);
   }


 
That worked for us then, perhaps this helps.

GL

Gareth.

MT DevMT Dev
Hi Simon,

Thanks for the reply. I am including the CreatedDate in the SOQL query and I can even see the values that are populated in the object all the way through the query call. In fact, if I check the value in the command window right before the last Return call, I can see a CreatedDate value. All fields I request are popluated except this one. My sample SOQL looks like:

SELECT ID, FirstName, LastName, CreatedDate, myCustomField__c FROM Contact

I was mainly curious if anyone has seen this type of behavior where some fields are not even in the list of the result set. I can past the entire web service result (or partial) if that would be useful.
MT DevMT Dev
Hi Gareth,

Thank you for the reply. This is very similar to the code I have written for querying salesforce. My problem is that one field I am looking for inparticular seems to disappear when I return an object of type Contact from my own Web Service. So after I have the results, I return an array of Contacts and a subset of the overall data is what gets returned.

Any thoughts in that regard?

Thanks,
Chad
Gareth DaviesGareth Davies
Do you mean that if your code was (say)
 
 


Contact getContact ()
{
   Contact myContact = doquery(); //Replace with code we saw earlier
   System.Writeline (Contact.CreatedDate.ToString());
}
 
Contact myReturnedContact = getContact();
System.WriteLine (myReturendContact.CreatedDate.ToString());
 
Would give different results?
 
 

Message Edited by Gareth Davies on 04-23-2006 02:05 PM

MT DevMT Dev
Not quite different results. Here is the scenario:
 
My Web Service Side
sforce.Contact[] wsContactList[] = doquery();
 
// viewed at breakpoint: wsContactList[0].CreatedDate = 4/19/2006 3:26:09 AM
return wsContactList;
 
UI Side
sforce.Contact[] uiContactList = MyWebService.Get();
// viewed at breakpoint: uiContactList[0].CreatedDate = NULL
 
When I look at the xml returned from my web service, the CreatedDate field is not listed in the results (not that it is null, it isn't even listed). So even though the UI side knows of a field called CreatedDate, it will never see data in it.
 
This is all c# code in VS 2005.
 
Thoughts?
SuperfellSuperfell
So you're taking the results of the sforce API call and returning that from a .NET web service? in that case, its really important that the XXXSpecified fields are getting set, they should be true from the deserialization from the sforce API call, but you mentioned in an earlier post they were (this sounds like a .NET bug). If the XXXSpecifed flag is not true, then when .NET re-serializes the Contact, it won't include that field.
Gareth DaviesGareth Davies
Of course Simon is right (as always) - this one caught me once when writing back to Salesforce using the enterprise WSDL.
 
If the other fields you are using are string values this it is not necessary/possible to use "Specified" because it can test for a NULL value (the empty string "") which is not possible with a numeric/boolean value.
 
make sure you set this:

YourObject.CreatedDateSpecified = true;

and try it then.

Gareth.

 
 
MT DevMT Dev
This worked like a champ. In code, I set the CreatedDateSpecified field on a record to true and it worked as I expected. Was this designed to be a manually changed field or a .Net bug?
SuperfellSuperfell
It sounds to me like a .NET bug, if the field was in the original Web Services response, then the specified flag should be set by the deserialization code.
MT DevMT Dev
Ok. Thanks for all the help Gareth and Simon.

Cheers,
Chad

P.S. If there is a place I should go to report this, please let me know.