You need to sign in to do that
Don't have an account?
lowtek
Relationship Query result to PHP
Hi!
I'm relatively new to SOQL Relationship queries. I want to list the name of contact as well as the company name which happened to be on two different tables. My query is this..
SELECT c.Name, (SELECT a.Name FROM Company a) FROM Contacts c limit 2
but the result in APEX Explorer shows only one column and i have to colapse the row in oder to see the Company.Name. Is there a way to display it in a column? If this is not possible, how can i pull out the Company.Name and Contacts.Name result and display it in PHP.
thanks
I'm relatively new to SOQL Relationship queries. I want to list the name of contact as well as the company name which happened to be on two different tables. My query is this..
SELECT c.Name, (SELECT a.Name FROM Company a) FROM Contacts c limit 2
but the result in APEX Explorer shows only one column and i have to colapse the row in oder to see the Company.Name. Is there a way to display it in a column? If this is not possible, how can i pull out the Company.Name and Contacts.Name result and display it in PHP.
thanks
The SELECT c.Name, (SELECT a.Name FROM Company a) FROM Contacts c limit 1 syntax is used when querying sub-objects (related lists).
When querying parent/sibling objects, you want to use the following. SELECT Name, Account.Name FROM Contacts limit 1. Maybe they both work (not sure), but I successfully use the latter.
I am using the Partner WSDL and below is my output of the query above. As you can see, Relationship fields are held within the sobjects section of a particular record.
Code:
Here's the code I used to produce those results.
Code:
Hi Hemm. Thanks for replying to my post. I tried your query (SELECT Name, Account.Name FROM Contact limit 1) at Apex Explorer and the result still shows a single column instead of two (one for account.name and contact.name). I have to click on the [+] to display the account.name. Im not sure if this should be the expected result.
Thanks for the help.
Thanks Hemm... got your point finally. I tried it in PHP to display it in table however I'm not able to display out the Account.Name correctly. Can you help me with my PHP code? I believe my error is in $sObject->fields->Name, $sObject->fields->Name.
Thanks. I appreaciate you help very much!
//here is my PHP code to display the result in table
require_once ('./soapclient/SforcePartnerClient.php');
require_once ('./soapclient/SforceHeaderOptions.php');
$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection("./soapclient/partner.wsdl.xml");
$mylogin = $mySforceConnection->login(user@example.com, "******");
$queryString = 'SELECT Name, Account.Name FROM Contact LIMIT 2';
$queryResult = $mySforceConnection->query($queryString);
if ($queryResult->size > 0) {
print ('<hr><table border="1" cellpadding="0" cellspacing="0">');
print ('<td>Contact Name</td><td>Account Name</td>');
$records = $queryResult->records;
foreach ($records as $record) {
$sObject = new SObject($record);
printf('<tr>' .
'<td>%s</td><td>%s</td>' .
'</tr>'. "\r\n", $sObject->fields->Name, $sObject->fields->Name);
}
}
Here is the output in web browser: