+ Start a Discussion
Timothy WinterTimothy Winter 

Why do we use WHATID instead of the WHAT field on tasks?


In the Bulk Apex Triggers Trailhead piece we are told to use WhatId to set the related field of a new task. However, when I look at the actual fields of the Task object the field name is actually What. When I try to use What I get an error. How would I have known to use the WhatId name instead and why is this in general?

User-added image
Best Answer chosen by Timothy Winter
Amit Chaudhary 8Amit Chaudhary 8
Please check below post to see Task Field API name
1) https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_task.htm

The WhatId represents nonhuman objects such as accounts, opportunities, campaigns, cases, or custom objects. WhatIds are polymorphic. Polymorphic means a WhatId is equivalent to the ID of a related object. The label is Related To ID.



The WhoId represents a human such as a lead or a contact. WhoIds are polymorphic. Polymorphic means a WhoId is equivalent to a contact’s ID or a lead’s ID. The label isName ID.
If Shared Activities is enabled, the value of this field is the ID of the related lead or primary contact. If you add, update, or remove the WhoId field, you might encounter problems with triggers, workflows, and data validation rules that are associated with the record. The label is Name ID.


Let us know if this will help you

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please check below post to see Task Field API name
1) https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_task.htm

The WhatId represents nonhuman objects such as accounts, opportunities, campaigns, cases, or custom objects. WhatIds are polymorphic. Polymorphic means a WhatId is equivalent to the ID of a related object. The label is Related To ID.



The WhoId represents a human such as a lead or a contact. WhoIds are polymorphic. Polymorphic means a WhoId is equivalent to a contact’s ID or a lead’s ID. The label isName ID.
If Shared Activities is enabled, the value of this field is the ID of the related lead or primary contact. If you add, update, or remove the WhoId field, you might encounter problems with triggers, workflows, and data validation rules that are associated with the record. The label is Name ID.


Let us know if this will help you
This was selected as the best answer
Srinivas SSrinivas S
Hi Timothy,

For all the standard objects for the look up data type fields we need to append 'Id' additionally or else you cannot populate that field which will throw the error.

Examples:
owner --> ownerId
Account --> accountId

------------
Thanks,
Srinivas
- Please mark as solution if your problem is resolved.
Timothy WinterTimothy Winter
So if I understand this correctly, when I am looking at the standard Task object through Setup I am not able to see the API name, only the field name which was a bit misleading for the exercise. If the fields of standard obejcts through Setup were to show the API name like it does for custom objects I would have seen right away that we needed to use WhatId for any APEX coding.

I really appreciate the help on this topic!
Amit Chaudhary 8Amit Chaudhary 8
Yes, you are right. for Standard object field API name you can see on below post.
1) https://developer.salesforce.com/docs/atlas.en-us.aapi.meta/api/sforce_api_objects_list.htm