Salesforce | Fetch all the tasks related to an sfobject

|
| By Webner

Description: I have a situation where I want to fetch all the tasks related to the account object.

Solution: You get all the task records which belong to any of SF object using single SQL query.

For Single object:
For Example, I want to query task related to accounts:

Qry=[SELECT Id,subject,What.Type,whatId FROM Event WHERE What.Type IN ('Account')]

For Multiple objects :
If you want to query tasks of more than one sf object you can do in this way:

Qry=[SELECT Id,subject,What.Type,whatId FROM Event WHERE What.Type IN ('Account',’Opportunity’)]

Leave a Reply

Your email address will not be published. Required fields are marked *