You need to sign in to do that
Don't have an account?

SOQL query to get all leads and the last 2 Task Descriptions as columns
How can I get the Name, Company, Phone Website and the description from the last (Most recent) 2 Task associated with the Lead. I do need all of the leads so Querying the Task Table and using Who does not work for me.
I tried
SELECT Id, Name, FirstName, LastName, Company, Website, Phone, (SELECT Description FROM Task limit 1 ) FROM Lead
Didn't understand relationship 'Task' 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.
How do you relate these two tables?
The relationship name is Tasks however you are using Task in your query.
Modify it as
SELECT Id, Name, FirstName, LastName, Company, Website, Phone, (SELECT Description FROM Tasks limit 1 ) FROM Lead
Cheers!
Prafull
All Answers
The relationship name is Tasks however you are using Task in your query.
Modify it as
SELECT Id, Name, FirstName, LastName, Company, Website, Phone, (SELECT Description FROM Tasks limit 1 ) FROM Lead
Cheers!
Prafull
Hi
Try with below query you will get last 3 Task Descriptions
SELECT Id, Name, FirstName, LastName, Company, Website, Phone, (SELECT Description FROM Tasks order by lastmodifieddate limit 2 ) FROM Lead