Skip to content
Advertisement

Error executing simple select query on salesforce

I’m trying to execute a query:

    <?php
    
    define("USERNAME", "myMail");
    define("PASSWORD", "mypass");
    define("SECURITY_TOKEN", "myToken");
    
    require_once ('soapclient/SforcePartnerClient.php');
    
    
    $mySforceConnection = new SforcePartnerClient();
    $mySforceConnection->createConnection("wsdl.jsp.xml");
    $mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);
    
    
    $query = "SELECT email__c FROM user__c";
    $response = $mySforceConnection->query($query);
    $queryResult = new QueryResult($response);
    ?>

But I get this error:

Fatal error: Uncaught SoapFault exception: [soapenv:Client] Element {}item invalid at this location in /Library/WebServer/Documents/force/soapclient/SforceBaseClient.php:797 Stack trace: #0 /Library/WebServer/Documents/force/soapclient/SforceBaseClient.php(797): SoapClient->__call(‘query’, Array) #1 /Library/WebServer/Documents/force/soapclient/SforceBaseClient.php(797): SforceSoapClient->query(Array) #2 /Library/WebServer/Documents/force/dummy.php(18): SforceBaseClient->query(‘SELECT email__c…’) #3 {main} thrown in /Library/WebServer/Documents/force/soapclient/SforceBaseClient.php on line 797

I’m not sure what I’m doing wrong. I’m using the Workbench SOQL Salesforce, and the query works good. What is wrong?

Advertisement

Answer

It looks like your Sales Force query should work well – however I’m not familiar with the “QueryResult” function, perhaps try to dump that line and see if it works. That may be for only one result, basically we normally just iterate through the records like this:

// Iterate through SF records
foreach ($response->records as $record) {
    //do something with $record here.
    print_r($record);
}
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement