GOAL
When a Lead is converted in Salesforce, its Tasks and Activities are automatically associated with the newly created Contact, Account, or Opportunity. However, once a Lead is converted, its IsConverted
field is set to true
, and its record is generally hidden from typical Lead queries. However, Tasks that were originally associated with the Lead remain in Salesforce and can be queried, but they’ll now point to the new Contact, Account, or Opportunity instead.
To query Tasks associated with converted Leads, here’s what you can do:
WORKAROUND
We can use ContactId or AccountId to query
List<Task> tasks = [SELECT Id, Subject, WhoId, Who.Name, FROM Task WHERE AccountId = lead.ConvertedAccountId and; CreatedDate < lead.ConvertedDate];