Find your content:

Search form

You are here

Selecting the "What" field in a Task using an SOQL request


I'm looking for a way to do a SOQL request to get a Task record, but I keep ending up with this error:

Error: Compile Error: No such column 'What' on entity 'Task'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 59 column 25

The 'What' field is labeled as 'Related To' (it's a standard field of the Activity object).

Here's my request generating this error:

Task task = [SELECT Type FROM Task WHERE What = :this.person.Id];

Thanks for your solutions.

Attribution to: jpmonette

Possible Suggestion/Solution #1

The relationship is called What, to compare with the Id, use WhatId

Task task = [SELECT Type FROM Task WHERE WhatId = :this.person.Id];

You could also use

Task task = [SELECT Type FROM Task WHERE What.Id = :this.person.Id];

Attribution to: techtrekker

Possible Suggestion/Solution #2

Take a look here as well - there were some updates in winter 13 that expanded this functionality: SOQL Polymorphism

Attribution to: BritishBoyinDC
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content