+ Start a Discussion
tedbowtedbow 

EmailMessage Fields not returning from Query in PHP

I am having problems querying email messages through PHP. Here is my code:

 

 

require_once("login.php");
$type = "EmailMessage";
$objectType = $mySforceConnection->describeSObject($type);
foreach($objectType->fields as $field){
$fields[] = $field->name;
}
$query = "select ".implode(",",$fields)." from $type";
print "$query<br />";

$result = $mySforceConnection->query($query);
print_r($result);

 

 As you can see I use "describeojbect" to get all the fields for the type EmailMessage.  Then I build a query with all of the fields.  When I get back the records though they only contain the "id" field. Here is my result:

 

select Id,ParentId,ActivityId,CreatedById,CreatedDate,LastModifiedDate,LastModifiedById,SystemModstamp,TextBody,HtmlBody,Headers,Subject,FromName,FromAddress,ToAddress,CcAddress,BccAddress,Incoming,HasAttachment,Status,MessageDate,IsDeleted from EmailMessage
stdClass Object
(
[done] => 1
[queryLocator] =>
[records] => Array
(
[0] => stdClass Object
(
[Id] => 02sA0000000Cnm1IAC
)

[1] => stdClass Object
(
[Id] => 02sA0000000CnnAIAS
)

[2] => stdClass Object
(
[Id] => 02sA0000000Cnp2IAC
)

[3] => stdClass Object
(
[Id] => 02sA0000000CnlrIAC
)

[4] => stdClass Object
(
[Id] => 02sA0000000CnmvIAC
)

[5] => stdClass Object
(
[Id] => 02sA0000000CnteIAC
)

[6] => stdClass Object
(
[Id] => 02sA0000000CnvuIAC
)

[7] => stdClass Object
(
[Id] => 02sA0000000CnlwIAC
)

[8] => stdClass Object
(
[Id] => 02sA0000000Co9IIAS
)

[9] => stdClass Object
(
[Id] => 02sA0000000Co9EIAS
)

)

[size] => 10
)

 

If I do this for other types such as "Contact" it doesn't have this issue, all the fields are returned.  Any ideas why no fields are returning?  If I take the id's returned and paste them into the browser with correct url, it shows me the email.

 

Thanks,

Ted

 

Best Answer chosen by Admin (Salesforce Developers) 
tedbowtedbow

Figured it out with a bit of searching.  The problem was the the wdsl file was being cached by php

  You can get around it by turning it off: 

See this wiki page:
http://wiki.apexdevnet.com/index.php/Turning_off_WSDL_cache

 

Strange that describeSObject method was working to get the correct fields.  I guess it is not reading them from the wsdl file.  Anyways it fixed the problem with the custom object also.

All Answers

phpandsfdcphpandsfdc
Strange.  This is behaving correctly for me with the Enterprise WSDL/PHP Toolkit 13.1.  Which WSDL/toolkit version are you using?
tedbowtedbow

Stranger - I am also using Enterprise WSDL/PHP Toolkit 13.1.

 

Maybe b/c I using this with my developer salesforce.com account?

phpandsfdcphpandsfdc
Huh.  I just tested on my developer account, and the EmailMessage object doesn't exist in the WSDL.  Out of curiosity, if you generate a new WSDL, is the EmailMessage object still there?  I added the EmailMessage passage to the Enterprise WSDL, but it's still getting a SOAP fault from the server (INVALID_TYPE).
Message Edited by phpandsfdc on 12-21-2009 11:48 AM
tedbowtedbow

I regenrated the wsdl.  EmaiMessage is there.

 

<complexType name="EmailMessage"> <complexContent> <extension base="ens:sObject"> <sequence> <element name="ActivityId" nillable="true" minOccurs="0" type="tns:ID"/> <element name="Attachments" nillable="true" minOccurs="0" type="tns:QueryResult"/> <element name="BccAddress" nillable="true" minOccurs="0" type="xsd:string"/> <element name="CcAddress" nillable="true" minOccurs="0" type="xsd:string"/> <element name="CreatedBy" nillable="true" minOccurs="0" type="ens:User"/> <element name="CreatedById" nillable="true" minOccurs="0" type="tns:ID"/> <element name="CreatedDate" nillable="true" minOccurs="0" type="xsd:dateTime"/> <element name="FromAddress" nillable="true" minOccurs="0" type="xsd:string"/> <element name="FromName" nillable="true" minOccurs="0" type="xsd:string"/> <element name="HasAttachment" nillable="true" minOccurs="0" type="xsd:boolean"/> <element name="Headers" nillable="true" minOccurs="0" type="xsd:string"/> <element name="HtmlBody" nillable="true" minOccurs="0" type="xsd:string"/> <element name="Incoming" nillable="true" minOccurs="0" type="xsd:boolean"/> <element name="IsDeleted" nillable="true" minOccurs="0" type="xsd:boolean"/> <element name="LastModifiedBy" nillable="true" minOccurs="0" type="ens:User"/> <element name="LastModifiedById" nillable="true" minOccurs="0" type="tns:ID"/> <element name="LastModifiedDate" nillable="true" minOccurs="0" type="xsd:dateTime"/> <element name="MessageDate" nillable="true" minOccurs="0" type="xsd:dateTime"/> <element name="Parent" nillable="true" minOccurs="0" type="ens:Case"/> <element name="ParentId" nillable="true" minOccurs="0" type="tns:ID"/> <element name="Status" nillable="true" minOccurs="0" type="xsd:string"/> <element name="Subject" nillable="true" minOccurs="0" type="xsd:string"/> <element name="SystemModstamp" nillable="true" minOccurs="0" type="xsd:dateTime"/> <element name="TextBody" nillable="true" minOccurs="0" type="xsd:string"/> <element name="ToAddress" nillable="true" minOccurs="0" type="xsd:string"/> </sequence> </extension> </complexContent> </complexType>

 

 

 

 

 

phpandsfdcphpandsfdc
hmm.  Hopefully someone else has some insight, sorry.  Without being able to query the object I'm not going to be much help :(
tedbowtedbow

,

If you are still listening....

When said the behavior was working correctly, was it working for the type "EmailMessage" or did you substitute another type?

 

Thanks

tedbowtedbow

ARRRRGGHHH!!

 

This is really aggrevating.  I created custom object "Message".  I exported my wsdl and when I query the object in the same manner as above it also comes back with only "Id" in fields.   Here is the definition in the WSDL.

 

 

<complexType name="Message__c"> <complexContent> <extension base="ens:sObject"> <sequence> <element name="ActivityHistories" nillable="true" minOccurs="0" type="tns:QueryResult"/> <element name="Attachments" nillable="true" minOccurs="0" type="tns:QueryResult"/> <element name="Contact__c" nillable="true" minOccurs="0" type="tns:ID"/> <element name="Contact__r" nillable="true" minOccurs="0" type="ens:Contact"/> <element name="CreatedBy" nillable="true" minOccurs="0" type="ens:User"/> <element name="CreatedById" nillable="true" minOccurs="0" type="tns:ID"/> <element name="CreatedDate" nillable="true" minOccurs="0" type="xsd:dateTime"/> <element name="Events" nillable="true" minOccurs="0" type="tns:QueryResult"/> <element name="IsDeleted" nillable="true" minOccurs="0" type="xsd:boolean"/> <element name="LastActivityDate" nillable="true" minOccurs="0" type="xsd:date"/> <element name="LastModifiedBy" nillable="true" minOccurs="0" type="ens:User"/> <element name="LastModifiedById" nillable="true" minOccurs="0" type="tns:ID"/> <element name="LastModifiedDate" nillable="true" minOccurs="0" type="xsd:dateTime"/> <element name="Name" nillable="true" minOccurs="0" type="xsd:string"/> <element name="Notes" nillable="true" minOccurs="0" type="tns:QueryResult"/> <element name="NotesAndAttachments" nillable="true" minOccurs="0" type="tns:QueryResult"/> <element name="OpenActivities" nillable="true" minOccurs="0" type="tns:QueryResult"/> <element name="Owner" nillable="true" minOccurs="0" type="ens:Name"/> <element name="OwnerId" nillable="true" minOccurs="0" type="tns:ID"/> <element name="ProcessInstances" nillable="true" minOccurs="0" type="tns:QueryResult"/> <element name="ProcessSteps" nillable="true" minOccurs="0" type="tns:QueryResult"/> <element name="SystemModstamp" nillable="true" minOccurs="0" type="xsd:dateTime"/> <element name="Tasks" nillable="true" minOccurs="0" type="tns:QueryResult"/> </sequence> </extension> </complexContent> </complexType>

 

 Has anybody had luck querying custom objects in PHP?

 

Thanks

 

tedbowtedbow

Figured it out with a bit of searching.  The problem was the the wdsl file was being cached by php

  You can get around it by turning it off: 

See this wiki page:
http://wiki.apexdevnet.com/index.php/Turning_off_WSDL_cache

 

Strange that describeSObject method was working to get the correct fields.  I guess it is not reading them from the wsdl file.  Anyways it fixed the problem with the custom object also.

This was selected as the best answer
jblockjblock

I had this problem, and I solved it... but it makes no sense.

My PHP code was not reading in fields from the default "EmailMessage" table that salesforce was sending along the php web service client library api.

I tried all sorts of PHP wsdl refreshing and cache clearing but nothing would work. I tried changing the wsdl file name and using the cache clearing command. Didn't work.

Using the Zend Studio debugger, I could see that php would get the data I wanted in a raw xml response by inspecting the underlying SoapClient __last_response value, but when the soap client would try to parse it, the resultant object would not have the fields from the EmailMessage table I was looking for loaded.... it would only have the Id values.

After trying anything that was sensible, I then revered to trying ridiculous things like restarting my eclipse IDE. That didn't work.

I then wondered why it was that when I go to download the Enterprise WSDL file, i was prompted about something relating to a "Salesforce for Google AdWords" before I could get my WSDL file.

 

I therefore deleted the app from our salesforce account (in the sandbox) called "Salesforce for Google AdWords". This caused all of the tables, that the Google For Adwords app had created, to be deleted. I then came back to the page where you get your Enterprise WSDL file... and I didnt see the thing about "Salesforce for Google AdWords" anymore. I downloaded the updated wsdl file for our account, and then I saw my EmailMessage fields started appearing... what the?

I immediately resintalled the "Salesforce for Google AdWords" in my sandnbox, downloaded an updated wsdl file, and tried again. I was expecting to see the problem reading EmailMessages reappear.


However, the EmailMessage fields I was looking for.... were there! This makes no sense... I dont understand it. The version number of the "google for adwords app" was the same. I really do not understand what could have caused this.

Lesson Learned: If you ever find you are inexplicably missing fields in a SalesForce Webservice API result, the problem is almost certainly that there is something wrong with the wsdl file. The procedure above makes no sense, but is only evidence that it was ultimately changes to the wsdl file that make the problem go away... not changes to the php code itself.

mbeckwellmbeckwell

I'm glad you shared this-- Using the default enterprise WSDL that came with the PHP Toolkit, I was not able to see the fields you mentioned.

After replacing it with a freshly generated version from our SalesForce instance... I am now able to see the fields that were previously not showing up.

 

Lesson learned, indeed.