2

I'm trying to query for information using the PHP API (v20) and I am unable to query any custom object fields. The only one that appears to work is Id. It gives no error, in fact, the query itself works. It only returns the Id, whether or not I queried for it. Though, if I had not queried for it then the Id field is blank.

The following is a sample of what I get back from a query. I tried updating the enterprise.wsdl.xml to one tailored to my Org, but it still doesn't work. Is there something I am missing? I'm not aware of any place I can view logs of what took place (like you do with the bulk api on yourorg.my.salesforce.com/750).

QueryResult Object (
    [queryLocator] => 
    [done] => 1 
    [records] => Array (
        [0] => SObject Object (
            [type] =>
            [fields] =>
            [Id] => SFIDHERE
        )
    )
    [size] => 1
)

Sample of the query run that produces the above. (line breaks added for less scroll)

$results = $mySforceConnection->query(
    "SELECT Id, Name, Stage__c, Subtotal__c FROM Custom_Object__c WHERE AccountId = '$Id'"
);

1 Answer 1

4

Use the partner WSDL. Please note that you have to put this to URL like http://yourServer/yourPartnerWsdl.xml - it won't work using a local path like /var/www/whatever/yourPartnerWsdl.xml

You will get errors directly in PHP. Therfore your Error settings has to be set in php.ini to something like

error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT 

which might not be the default.

The following code should work after adjusting your paths

require_once ('../yourPathTo/soapclient/SforcePartnerClient.php');
define("USERNAME", "[email protected]");
define("PASSWORD", "yourPassword");
define("SECURITY_TOKEN", "yourToken");
$GLOBALS[sfBatchSize] = 100;
$GLOBALS[sfConnection] = new SforcePartnerClient();
$GLOBALS[sfConnection]->createConnection("http://yourServer/yourPartnerWsdl.xml");
$GLOBALS[sfConnection]->setEndpoint('https://test.salesforce.com/services/Soap/u/31.0');
$GLOBALS[sfConnection]->login(USERNAME, PASSWORD.SECURITY_TOKEN);

$query = "SELECT Metier__c, Profil__c, Secteur__c, TypeContrat__c, Id FROM Opportunity ";
$response = $GLOBALS[sfConnection]->query($query);
$records = $response->records;
while(!$response->done) {
    $response = $GLOBALS[sfConnection]->queryMore($response->queryLocator);
    $records = array_merge($records, $response->records);    
}
print_r($records);
4
  • You are simply amazing. Thank you, Uwe Heim! I would upvote you, but I don't have the points yet... Commented Mar 4, 2015 at 19:46
  • If it was helpful you might consider to upvote the question. Glad this worked for you. I did many years primarily PHP before I started with Salesforce and I'm happy to to assist, if I can. - I see - then come back later :-) Commented Mar 4, 2015 at 19:49
  • I'm just curious: which of the points mention was it in the end? I was only fishing for possible reasons. Could you drill it down? Commented Mar 4, 2015 at 20:07
  • Sorry, got my terms mixed. I didn't have enough rep, but do now. Upvoted you. I switched to Partner from Enterprise. Once I did that and did the createConnection() as you prescribed as well as the setEndpoint(), it worked magnificently. Commented Mar 4, 2015 at 21:52

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.