0

I use a Query to get all Contacts that were changed in the last "timeframe" like this:

SELECT AccountId, Id, Email, FirstName, LastName FROM Contact WHERE LastModifiedDate >= $timeframe

I also Need the Account name but for now I only make an additional Query like this:

SELECT Name FROM Account WHERE Id = '$AccountId'

How can I combine thees two so I only need one Query and have one result set? I tried to make a Join like with normal SQL and even tried some versions I found here and on the Docs but i seem to not get it right...

Salvat
  • 37
  • 1
  • 4
  • 1
    What are your tables and how are they related? – Alma Do Dec 05 '13 at 09:47
  • There is an Account Table with Data about the Company and a Contact Table with the data about a specific contact as you can see in my Selects - Please be mindfull that we talk about SOQL for Salesforce and not SQL. – Salvat Dec 05 '13 at 11:18

2 Answers2

0

This should get your result : SELECT AccountId, (select name from Account__r), Email, FirstName, LastName FROM Contact WHERE LastModifiedDate >= $timeframe

Bartley
  • 290
  • 2
  • 7
  • 21
  • Sadly not - Account is not a custom field like in your query, its the Account Table with the Information for an Account (Name, BillingAddress etc.) If I use SELECT AccountId, Id, (SELECT Name FROM Account), Email, FirstName, LastName FROM Contact LIMIT 10; I get a return from SF: ERROR at Row:1:Column:41 Didn't understand relationship 'Account' in FROM part of query call. – Salvat Dec 06 '13 at 00:49
0
SELECT Account.Name FROM Contact WHERE LastModifiedDate >= $timeframe

You don't need to append __r for relationships pre-defined by Salesforce.

Wilkin Ho
  • 178
  • 1
  • 1
  • 7