0

I have to get two different names pulled from this query, the Account Name and the Opportunity Name. Both are called "Name" under each object.

I am able to use a query to retrieve both of them, but I am unable to decipher between the two in order to actually echo/print or use them.

My Query is:

$query = "SELECT Name,Opportunity.Account.Name from Opportunity ";

$response = $mySforceConnection->query($query);

foreach ($response->records as $record) {

  echo $record->Name ."<br/>\n"; 
//echo $record->Opportunity.Account.Name ."<br/>\n";

echo "<br/>\n"; }

The only Name that is displayed is the opportunity Name (when trying different methods, I know the code above will only echo that)

I have made two seperate queries one from account and one from opportunity to ensure both are infact different things, and they are.

I have attempted to echo two "Name" records, both are just the opportunity name it doesn't recognize the account name.

And obviously what is commented out above as "Opportunity.Account.Name" isn't echoing the result, i am recieving an error instead.

I know using an alias is not supported in salesforce so that obviously didn't and won't work, by that I mean trying to do this:

Select Name as OppName

I am unable to find a different way to echo the records, I have done a lot of googling on the subject. Any help would be appreciated or a point in the right direction.

2 Answers 2

0

In my schema there is no Name field in the Opportunity object. There is Account Name and it is a lookup on Account Name in the Account object. You can view the schema builder by going to Setup > Schema Builder (it is under App Setup).

1
  • I have looked at my schema, they both exist, and i have pulled from each separately, but I need to pull them both together.
    – CoderDojo
    Aug 21, 2014 at 8:22
0

To be honest, I don't know why this worked. I'm new to SOAP and Salesforce, so I was just trying different things to get it working. But if anyone else has this problem, this is how I fixed it.

I displayed the account name by using this to echo it:

echo $record->Account->Name ;

The query is still the same as in the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.