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.

  • if techtrekker's answer worked for you please upvote it or select it as the selected answer if you are able to. – Caspar Harmer Nov 23 '12 at 22:32

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];
| improve this answer | |
  • Thanks, it's working. Is it the same thing with RecordType ? – jpmonette Nov 23 '12 at 22:20
  • Yes RecordTypeId or RecordType.Id – techtrekker Nov 23 '12 at 22:32
  • 1
    To determine this in the future for any object or field try exploring the Salesforce schema with the Force.com explorer wiki.developerforce.com/page/ForceExplorer – Born2BeMild Nov 26 '12 at 9:35

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.