8

I have a junction object called Trip_meeting__c to connect Event to Business_trips__c. Because you can't create a lookup to Event, I am using a text field Meeting__c to hold the Event Id and will query on that field.

I can do a semi-join on the junction to the custom object parent since it is linked via lookup:

Event EV;

public List <Business_trip__c> getBizTrips (){
    return [
        SELECT id, name, ownerID, start_date__c, end_date__c, location__c
        FROM business_trip__c WHERE Id IN (
            SELECT Business_trip__c FROM Trip_meeting__c
            WHERE Meeting__c =: String.valueOf(EV.id)
        )
    ];
}

But doing the same for the Event runs an error:

Business_Trip__c BT;

public List <Event> getEvents(){
    return [
        SELECT Id FROM Event WHERE Id IN (
            SELECT Meeting__c FROM Trip_meeting__c WHERE Meeting__c =: BT.id
        )
    ];
}

semi join sub selects can only query id fields, cannot use: 'Meeting__c'

Since Meeting__c holds the Id of the Event, how can I query using this field?

2 Answers 2

8

You're going to need to do plain old pre-processing.

Set<String> meetingIds = new Set<String>();

for (Trip_Meeting junction : [
    SELECT Meeting__c FROM Trip_Meeting__c WHERE Business_Trip__c =: BT.id
]) meetingIds.add(junction.Meeting__c);

return [SELECT Id FROM Event WHERE Id IN : meetingIds];
0
0

Create a Set and populate it with all the values in Meeting__c.

Technically this field is a text field so that's why you can't use it in your query.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .