1

I have a trigger on Event where I'm querying the isconverted field of Lead but I'm getting this error:

System.QueryException: No such column 'isconverted' on entity 'Name'

I tried below queries:

select WhoId.isconverted from Event
select Who.isconverted from Event
3

Polymorphic queries are still not generally available, but the correct way to query fields through a polymorphic relationship is to use the TYPEOF clause:

SELECT
    TYPEOF Who
        WHEN Lead THEN IsConverted
    END
FROM Event WHERE Who.Type = 'Lead'

If you want to go that route, open a case with support to get SOQL Polymorphism enabled for your org. Or, you can just query all Lead records which have a related Event:

SELECT IsConverted FROM Lead WHERE Id IN (SELECT WhoId FROM Event)

Interestingly, it seems that you can pull in most fields that are common to Contact and Lead through this relationship, but nothing that is specific to one or the other.

Supported

SELECT Who.FirstName, Who.LastName, Who.Email FROM Event

Not Supported

SELECT Who.AssistantName FROM Event WHERE Who.Type = 'Contact'
SELECT Who.AnnualRevenue FROM Event WHERE Who.Type = 'Lead'
  • Does getting TYPEOF turned on allow you to actually write code like record.Who.IsConverted, or would you still have to use the SObject dynamic get field method? – sfdcfox Feb 15 '17 at 17:37
  • @sfdcfox Yes, I believe it allows you to pull in the queried fields directly. It's been years since I looked into it though. – Adrian Larson Feb 15 '17 at 17:39
2

Who.IsConverted would be correct, except that this field happens to be a Name field. The documentation describes all the possible fields you can use, which does not include object-specific fields such as Lead.IsConverted. You'll want to build a list of Lead Id values, then query those leads and put them in to a Map.

  • Even for Who.isconverted I'm getting this error – salesforce Developer Feb 15 '17 at 17:21
  • On accessing these documentation I'm getting this error Sorry, the document you are looking for doesn't exist or could not be retrieved. – salesforce Developer Feb 15 '17 at 17:21
  • @salesforceDeveloper That's odd. It works for me. Still, you can just use your favorite search engine to find the Salesforce SOAP API Developer's Guide, then search for the Name object. – sfdcfox Feb 15 '17 at 17:35
  • Works for me as well. – Adrian Larson Feb 15 '17 at 18:37

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.