[SalesForce] How to convert WhoId to text in formula field

I've to check whether the WhoId value is Contact or Lead. If I convert WhoId to text then I can check if by standard object prefix like '003' for Contact. So is there any possible way to convert WhoId to Text in formula fields?

I tried with the formula:

IF( BEGINS(TEXT(WhoID), 003),'Contact','Lead' )

which produces the error:

Incorrect parameter type for function 'TEXT()'. Expected Number, Date, DateTime, Picklist, received Lookup(Contact,Lead)

Best Answer

Use WhoId rather than Who.Id. Don't wrap it in the TEXT function either. The value is an Id which behaves as text already. This formula passes a syntax check just fine:

CASE(
    LEFT(WhoId, 3),
    "003", "Contact",
    "00Q", "Lead",
    ""
)

Please note if you are trying to access this data via SOQL, you do not even need a formula. You can query or filter on Who.Type.

SELECT count() FROM Task WHERE Who.Type = 'Lead'