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
EtienneCoutantEtienneCoutant 

Cannot retrieve AccountID or AccountName when Querying on Cases

I am using:
PHP toolkit-11_0b
PHP 5.1.6
Salesforce API version 11


I am trying to retrieve the Account name or id, when querying on Cases from the API, but I could not find a way to do that:

SELECT Id, Account.Name FROM Case --> Doe not work with PHP

SELECT Id, AccountId FROM Case --> No such column 'AccountId' on entity 'Case'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

SELECT Name, (SELECT Id FROM Cases WHERE Id = '".$MyCase->Id."') FROM Account --> Didn't understand relationship 'Cases' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.


Someone can help me on that?
Thanks a lot,
Etienne
Tran ManTran Man
Try this:

Code:
  $caseid = 'yourcaseid';
$query = "Select Id, Case.Account.Id from Case where Id = '$case'"; $response = $mySforceConnection->query($query); $queryResult = new QueryResult($response); print_r($queryResult);


The schema browser in the Force.com IDE is your friend.



Message Edited by Tran Man on 02-26-2008 03:30 PM
EtienneCoutantEtienneCoutant
Thanks a lot for your answer!
sissyphussissyphus
  $caseid = 'yourcaseid';
$query = "Select Id, Case.Account.Id from Case where Id = '$case'"; $response = $mySforceConnection->query($query); $queryResult = new QueryResult($response); print_r($queryResult);
 
 
But in this case, how would one refer to Case.Account.Id from PHP?
 
Say you use SObject to create an object to refer to your returned records. I could use $r->Id to get the first field, but how would I retrieve the second one...?
 
EtienneCoutantEtienneCoutant
I got the following working well:

Code:
  
$caseid = 'yourcaseid';
$query = "Select Id, Account.Name from Case where Id = '$caseid'";
$response = $mySforceConnection->query($query);
foreach($response->records as $ThisCase) {
$ThisCaseObject = new SObject($ThisCase);

//prints Case.Account.Name
echo $ThisCaseObject->sobjects[0]->fields->Name;
}


I would assume that you could use $ThisCaseObject->sobjects[0]->Id if your query is "Select Id, Case.Account.Id from Case where Id = '$caseid'";