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
JJUPOJJUPO 

First Step PHP Toolkit -- Query

Hello everyone,

 

I'm learning how to use the PHP toolkit, and I nedd some help. I want to query the Account Name field, so I do this

 

<?php

require_once ('sforce-php/soapclient/SforcePartnerClient.php');

try {
  $mySforceConnection = new SforcePartnerClient();
  $mySoapClient = $mySforceConnection->createConnection("sforce-php/samples/partner.wsdl.xml");
  $mylogin = $mySforceConnection->login(LOGIN,PASSWORD+TOKEN);

  $userResult = $mylogin->userInfo;
  
  $query = 'SELECT Id,Name from Account limit 5';
  $response = $mySforceConnection->query(($query));
  $sObject = new stdClass();
  foreach ($response->records as $record) 
  {
       print_r($sObject->Name);   
       print_r("<br>");
  
  }
  
} catch (Exception $e) {
  echo $e->faultstring;
}
?>

 

But I get: Notice: Undefined property: stdClass::$Name

 

 

Any advice?

 

 

Thanks in advance

 

 

Best regards

 

JJUPO

TPOLTPOL
I'm pretty new to Salesforce but I'd take a look in the stdClass class, it's telling you the Name property does't exist. Are you supposed to use $sObject->firstName and $sObject->lastName?
ecivsecivs

The SQL you are using isn't compaitble with SalesForce. That's a MySQL query. You have to use Oracle SQL (SOQL) (yes, it's different).

The  LIMIT 5 is not valid. You need to look at the response object for success or failure:

 

 

    $mQR = $mSforceConnection -> query( $mSQL );
    if ( $mQR === false || $mQR -> done == false )
    {
        return false;
    }
    if ( count( $mQR -> records ) < 1 )
    {
        // No record(s) returned.
        return null;
    }