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
adi0908adi0908 

$record->fields->Firstname doesn't give me the Firstname of Contact field

Hello, I'm trying the simple query from the docu.

using the actual  version of php toolkit.

only to try out Enterprise wsdl (works fine) and Partner wsdl on the other side.

partner wsdl doesn't give me the expected results.

I only see the id of the contact, and the other fields are combined in any- field.

I want to give out the Firstname, Lastname and so on.

here is the code:

<?php
session_start();
require_once ('soapclient/SforcePartnerClient.php');
require_once ('soapclient/SforceHeaderOptions.php');
//require_once ('soapclient/SforceEnterpriseClient.php');
define ("USERNAME", "myuser@blabla.de");
define("PASSWORD", "mypw");
define("SECURITY_TOKEN", "mytoken");

try {
    $mySforceConnection = new SforcePartnerClient();
    $mySforceConnection->createConnection("soapclient/partner.wsdl.xml");
    if (isset($_SESSION['partnerSessionId'])) {
        $location = $_SESSION['partnerLocation'];
        $sessionId = $_SESSION['partnerSessionId'];
        $mySforceConnection->setEndpoint($location);
        $mySforceConnection->setSessionHeader($sessionId);
        echo "Used session ID for partner<br/><br/>\n";
    } else {
        $mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);

        $_SESSION['partnerLocation'] = $mySforceConnection->getLocation();
        $_SESSION['partnerSessionId'] = $mySforceConnection->getSessionId();

        echo "Logged in with partner<br/><br/>\n";
    }
    $query = "SELECT Id, FirstName, LastName, Phone from Contact";
    $response = $mySforceConnection->query($query);
    $queryResult = new QueryResult($response);
    foreach ($queryResult->records as $record) {
            print_r($record);

            echo $record->Id . ": " . $record->fields->FirstName . " "
            . $record->fields->LastName . " " . $record->fields->Phone . "<br/>\n";            
    }
} catch (Exception $e) {
    echo "Exception ".$e->faultstring."<br/><br/>\n";
    echo "Last Request:<br/><br/>\n";
    echo $mySforceConnection->getLastRequestHeaders();
    echo "<br/><br/>\n";
    echo $mySforceConnection->getLastRequest();
    echo "<br/><br/>\n";
    echo "Last Response:<br/><br/>\n";
    echo $mySforceConnection->getLastResponseHeaders();
    echo "<br/><br/>\n";
    echo $mySforceConnection->getLastResponse();
}
?>

 

 

the doc says, that it works with ...

$record->fields->FirstName

 

but this works not in my case.

 

may be a simple beginner mistake - can you help me?

 

thanks a lot,

 

Adi

 

Park Walker (TAGL)Park Walker (TAGL)

This looks to be correct. What does the print_r($record) statement produce?

adi0908adi0908

hello redsummit,

print_r($record) gives me for example:

stdClass Object ( [type] => Contact [Id] => Array ( [0] => 003d000000P84mVAAR [1] => 003d000000P84mVAAR ) [any] => KonradXxx0171-2323052 ) Array:

stdClass Object ( [type] => Contact [Id] => Array ( [0] => 003d000000P84kHAAR [1] => 003d000000P84kHAAR ) [any] => SonjaSyyy08102-8749027 ) Array:

stdClass Object ( [type] => Contact [Id] => Array ( [0] => 003d000000U6yGOAAZ [1] => 003d000000U6yGOAAZ ) [any] => AdiSchlachtertest Array:

 

seems likecontakt- id is separated and lastname, firstname,phone is collected in [any]...

 

I'm sure it's a very beginner problem, but i don't  understand how it works.

the developer  sample  for partner wsdl is

 

echo $record->Id . ": " . $record->fields->FirstName . " "
            . $record->fields->LastName . " " . $record->fields->Phone . "<br/>\n";

 

and produces me only "array:"

 

thanks for your answer, I'm sure you can help me becoming better ;-)

 

Adi

 

 

adi0908adi0908

hello redsummit,

I think it was basic programmer problem ;-)

 

$queryResult = new QueryResult($response);
    foreach ($queryResult as $record) {
            print_r($record);
            echo $record->Id . ": " . $record->fields->FirstName . " "
            . $record->fields->LastName . " " . $record->fields->Phone . "<br/>\n";
    }

produces the expected output.

 

foreach ($queryResult->records as $record) was wrong !!!!!

 

sorry for that stupid question !!!

 

Adi