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
gokubigokubi 

error with query result in php toolkit

I'm working in the php toolkit for the first time, but I am proficient in the ajax toolkit.

I have successfully upserted some records to sf.com, but I'm having problems getting some query results back. This code is erroring out on me:

   Code:
 $Account_query = "Select Id, Name from Account where Dot_Project_Number__c = '".$company_id."'";
 $Account_query_Result = $mySforceConnection->query($Account_query);

 foreach ($Account_query_Result as $ThisAccount) {
   $sObject = new SObject($ThisAccount); //error on this line
   $Account_Id = $sObject->Id;
 }
The error is:

PHP Notice:  Trying to get property of non-object in C:\...\SforcePartnerClient.php on line 47

Any thoughts on why this isn't working?

Thanks,
Steve


adamgadamg
are you sure the query is valid?  (ie results results) Can you try a simple query and see if that works?
Tran ManTran Man
Try

var_dump($Account_query_Result);

to see what you actually get back.  And start with a simple query as Adam suggested.

gokubigokubi
The query is valid, and when I look at the result.size, I get 1, so I'm getting something back. It just doesn't behave like it's supposed to...I'll try Tran Man's advice and see what I learn.

Steve
Tran ManTran Man
One other thought, the records are actually displayed in in the "records" attribute of the result object.

This is the logic to use:

$response = $mySforceConnection->query($Account_query);
if ($response->size > 0) {
if ($response->size == 1) {
$recs = array (
$response->records
);
} else {
$recs = $response->records;
}
}

foreach ($recs as $ThisAccount) {
$sObject = new SObject($ThisAccount); //error on this line
$Account_Id = $sObject->Id;
}


Another user has informed me that there is an error in instructions.html.  I will update this on Monday and refresh the zip.

Message Edited by Tran Man on 03-12-2006 08:25 PM

Park Walker (TAGL)Park Walker (TAGL)
Since this logic must always be included when processing the results of a query, wouldn't it be nice if the query call did this for you and cast a single record result as an array. Then you would know to expect an array of records, regardless of the inconsistent results of the query call.

Just a thought.

Park
SynchroSynchro
I quite agree - that is what I did in the php5 class I wrote before the php5 toolkit came out. Inconsistent return formats are evil!
gokubigokubi
Agreed! Thanks for the advice Tran Man, that did the trick.

Steve
Tran ManTran Man


Redsummit wrote:
Since this logic must always be included when processing the results of a query, wouldn't it be nice if the query call did this for you and cast a single record result as an array. Then you would know to expect an array of records, regardless of the inconsistent results of the query call.

Just a thought.

Park


Great idea.  This will be in the next php toolkit refresh which I have submitted.  I'll let everyone know when it gets pushed out.

Thanks
SynchroSynchro
Excellent news. I've been looking at the current release and I've done quite a lot of cleaning up (coding standards & comments, stray =&, comparisons to NULL, misplaced bitwise operators etc) - would you like a patch for what I've done? Would you prefer it against your CVS HEAD (which I assume is on sourceforge) instead of the release version?
SynchroSynchro
I had another general observation - why did you make SforceBaseClient a new class with a SoapClient property instead of extending the built-in SoapClient class? That way you'd save yourself quite a lot of $this->sforce->... syntax, plus it just seems to be the 'right' way to do it.
Tran ManTran Man
The refresh fixed a lot of those things you mentioned but it has not yet been pushed out.  The source does not live on sourceforge, but I would like to see what you have done, nonetheless. I'll send you the latest zip and we can sync up from there. 

Thanks.


Synchro wrote:
Excellent news. I've been looking at the current release and I've done quite a lot of cleaning up (coding standards & comments, stray =&, comparisons to NULL, misplaced bitwise operators etc) - would you like a patch for what I've done? Would you prefer it against your CVS HEAD (which I assume is on sourceforge) instead of the release version?


Message Edited by Tran Man on 03-14-2006 10:04 AM

SynchroSynchro
I just grabbed the 1.0.1 version - I'm happy to report that you fixed nearly everything that I did!

The extra changes I did in SforceBaseClient.php were using is_null() instead of ==NULL (a safer comparison), and using the logical 'and' operator instead of the bitwise operator & (I suspect you may have intended to use && which does a low-precedence logical and). I also did some cleanup in the comment formatting and removed all trailing whitespace. It might be just me, but I always use ONLY tabs for indenting - I can understand using all spaces, but mixing them is definitely out ;^)

While I welcome the addition of _handleRecords(), it might have been worth sticking a warning on the docs as it may break code that's expecting the old behaviour. I think it should also be marked protected as nothing outside the class should have any use for it.

In SforcePartnerClient.php I changed constructors to use __construct, and switched convertFields to use str_replace instead of the much slower ereg_replace.

The unit tests run ok, apart from a bunch of notices about using stdClass undeclared properties, and the report generation fails saying "Could not find file ..\..\infra\php/phpunit2-frames.xsl"

How would you like patches submitted? To sf.net patches? Or should I email stuff to you?