3

I'm trying to get a phone number from an Account with a completed Event in SOQL. Here is my query

select Phone from Account where Name in (select School_Name__c from Event where Visit_Status__c = 'Completed')

I get an error that says

Entity 'Event' is not supported for semi join inner selects

Is this possible to do in one SOQL query?

3

No. You can only do a Left Inner Join on Id values anyway. Trying to join on Name would never work, regardless of which objects are involved. If you don't have too many Event records and you're in an Apex context, it wouldn't be an excessive amount of extra work/governor consumption to just loop through and collect the values:

Set<String> names = new Set<String>();
for (Event record : [
    SELECT TransAm_School_Name__c FROM Event
    WHERE TransAm_School_Name__c != null
    AND TransAm_School_Visit_Status__c = 'Completed'
]) names.add(record.TransAm_School_Name__c);
List<Account> schools = [SELECT Name FROM Account WHERE Name IN :names];
  • I need it to be SOQL – gary69 Jun 14 '17 at 21:56
  • 2
    @gary69 Then the answer is it's impossible in one query. You would need to do some batches or data loading to massage the data to a point where you could do it with just one query. – Adrian Larson Jun 14 '17 at 21:57

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.