You need to sign in to do that
Don't have an account?
Cortex
Querying for Custom Field
When I query a custom field from a custom object it does not return the custom field to me, I do however get the non-custom fields when I run the query.
I try the exact same query in sforce Explorer and it works exactly as it should.
Why am I unable to retrieve this data?
Query: SELECT Id, Custom_Field__c FROM custom_object__c
Results: Just "Id" (No error is issued).
-Cortex
I wanted to learn how it actually worked, so I wrote my own and also the Toolkit looked a little too complicated for my purposes. In addition I had some problems with it when I first investigated, although I couldn't tell you what they were now, and frankly just didn't trust the toolkit, so I wrote my own.
I would highly recommend that you try it.
Ok, this is VERY interesting. I tried doing the same thing using the PHP toolkit and got the same problem. Any thoughts now?
* Make sure you use the partner wsdl
* For each result obj, instantiate an SObject.
$myobj = new SObject($objinstance);
THen you can access the fields as so:
echo $myobj->Id;
echo $myobj->.FirstName;
Interesting. I got it to work with the PHP toolkit, but I noticed an odd thing. If I query for all the fields in my custom object I get this result:
Here's some code to reproduce the problem:
<?php
require_once ('soapclient/SforcePartnerClient.php');
try {
$sforce = new SforcePartnerClient();
$soap_client = $sforce->createConnection("partner.wsdl.xml");
$sforce_login = $sforce->login("username", "password");
$login_result = $sforce_login->userInfo;
echo $login_result->userFullName.', your session id is '.$sforce_login->sessionId;
} catch (Exception $e) {
echo $e->faultstring;
}
$soql = "
SELECT
AccountId,
AssistantName,
AssistantPhone,
Birthdate,
CreatedById,
CreatedDate,
Department,
Id,
FirstName,
LastName,
SystemModstamp
FROM
Contact
";
try {
$result = $sforce->query($soql);
} catch (Exception $e) {
var_dump($e);
}
foreach($result->records as $record) {
var_dump($record);
$myobj = new sObject($record);
var_dump($myobj);
}
?>
https://wiki.apexdevnet.com/index.php/PHP_1.0.x_Toolkit
So, I came up with the following test case:
Lead field values (set via SalesForce end-user UI):
Id = [auto-assigned]
FirstName = "Joe"
LastName = "Blow"
Email = "" (0-length)
An offending (offensive?) snippet of code [minus proper exception handling for brevity's sake]:
function getLeadFromSalesForce( $sfObjectID ) {
$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection(SALESFORCE_PARTNER_WSDL_PATH);
$mylogin = $mySforceConnection->login($SFLogin, $SFPassword);
$flds = 'Id, FirstName, LastName, Email';
$response = $mySforceConnection->retrieve($flds, 'Lead', array($sfObjectID));
if(is_null($response)) {
return false;
} else {
$sObj = new SObject($response);
return $sObj;
}
}
At this point, if I var_export(), var_dump(), or print_r() the return value of the function, I see the following where the "empty" field values are supposed to be; this is true for every field requested in the call to SforcePartnerClient::retrieve() that otherwise appears as blank in the SalesForce UI:
There always seems to be a line break/newline, and the value is always an object of type SimpleXMLElement.
What's up with this? Why can't I just get a NULL value or a 0-length string back? My ultimate goal is to persist these "string" values in the user's session, but the presence of the SimpleXMLElement objects in the results irreperably corrupts my session data (since one isn't supposed to store objects inside the $_SESSION superglobal unless they're serialized)!!
I'd rather not make the edits to the PHP Toolkit myself just to get what I need returned by the SforcePartnerClient object instance; how else can I make this happen without having to iterate through the entire field list and call something like is_object() on every dang field?
Thanks,
.e