soql – What is the easiest way to get a Task WhatId parent’s RecordType?
I need to query a Task’s related to (i.e. WhatId) parent’s recordtype
- The Task
Whatrelationship is polymorphic and hence itsWhatIdcould point atAccount,Opportunity,myCustomObject__c, etc. These objects might or might not have record types.
I looked at the SOQL reference guide on polymorphic querying and I see some options that aren’t really practical
SELECT Id, What.Type FROM Task// just tells meSObjectTypeof the parentSELECT Id, What.Name FROM Task// returns the parent’sNamefield
and
SELECT
TYPEOF What
WHEN Account THEN Id, RecordType.Name
WHEN Opportunity THEN Id, RecordType.Name
END
FROM Task
but this isn’t scalable as new SObjects are added to the org
Read more here: Source link
