WhoID in Salesforce refers to people things. So that would be typically a Lead ID or a Contact 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 ID or a lead ID. The label is Name ID.

Example: Use of whoId in salesforce. Create a visualforce page:

<apex:page controller=”checkwhocontroller” >
<apex:pageBlock>
<apex:pageBlocktable value=”{!mywho}” var=”w”>
  <apex:column width=”400px”>
                  <apex:facet name=”header”>Name</apex:facet>
<apex:outputLink value=”/{!w.whoid}” >
                        <apex:outputText value=”{!w.who.name}”/>
                   </apex:outputLink>
        </apex:column>
        </apex:pageBlocktable>
</apex:pageBlock>
</apex:page>

Apex Class:
public class checkwhocontroller {
    public Task[] getMywho() {
    task[] mytaskArray = new task[]{};
    mytaskArray=[SELECT Subject, Who.Name FROM Task LIMIT 20];

        return mytaskArray;
    }
}

WhatID in Salesforce refers to object type things. That would typically be an Account ID or an Opportunity ID. 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.

Example: Create a task whenever a case is inserted into salesforce.

trigger CaseTrigger on Case (after insert, after update){
    List<task> taskList = new List<task>();
    for (Case c : trigger.new){
        //Create a task when case is created
        if(trigger.isInsert){
            task t = new task();
            t.whatId = c.Id;
            t.Subject = c.Subject;
            taskList.add(t);
        }
    }
insert taskList;
}

Leave a Reply

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