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
lplevalpleva 

Trouble with basic toolkit example

Hi everyone,

 

I am having trouble getting the code below to work. It's pretty much copy/paste from the examples that SF provides in its documentation, hence my confusion:

 

<?php

define("USERNAME", "");
define("PASSWORD", "");
define("SECURITY_TOKEN", "");

require_once ('http://moneythink.org/apps/soapclient/SforceEnterpriseClient.php');

$mySforceConnection = new SforceEnterpriseClient();
$mySforceConnection->createConnection("http://moneythink.org/apps/soapclient/enterprise.wsdl.xml");
$mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);

$query = "SELECT Id, FirstName, LastName, Phone from Contact";
$response = $mySforceConnection->query($query);

echo "Results of query '$query'<br/><br/>\n";
foreach ($response->records as $record) {
    // Id is on the $record, but other fields are accessed via the fields object
    echo $record->Id . ": " . $record->fields->FirstName . " "
        . $record->fields->LastName . " " . $record->fields->Phone . "<br/>\n";
}

?>

 I am very new to PHP/working with API's, so my apologies if I made any basic mistakes. When I try to execute http://moneythink.org/apps/sf-app.php, which contains the code above, I just get a "Server Error" message. 

Wizno @ ConfigeroWizno @ Configero

Have you made any progress with this?

Park Walker (TAGL)Park Walker (TAGL)

One problem is that you are mixing the Enterprise and Partner access methods. If you are using the Enterprise WSDL then there is no fields array; you fields are defined at the top level. You would access $record->FirstName, not $record>fields->FirstName.

 

Without the error that's being thrown (look in your server error log or PHP log) it's impossible to know what else might be a problem.

 

If you have already resolved the problem please post the solution.

 

Park