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
GaGrizzlyGaGrizzly 

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?

 

Best Answer chosen by Admin (Salesforce Developers) 
Prafull G.Prafull G.

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

Prafull G.Prafull G.

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

This was selected as the best answer
dotnet developedotnet develope

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