0

enter image description here

I have some custom objects displayed on schema. I need return vacancies which have last active interview at least week ago. I have some query:

List<Vacancy__c> ids = new List<Vacancy__c>();

    for(Application_Proces__c ap : [
            SELECT Vacancy__r.Id, Vacancy__r.Name, Vacancy__r.Status__c, Vacancy__r.Requirements__c, Vacancy__r.Priority__c, Vacancy__r.Rate__c
            FROM Application_Proces__c
            WHERE Id NOT IN (
                    SELECT Application_Process__c
                    FROM Interview__c
                    WHERE Meeting_Date__c = LAST_N_DAYS:7
                    OR Meeting_Date__c > TODAY
            ) AND Status__c = 'Open'
    ]) {
        ids.add(ap.Vacancy__r);
    }

I need to rewrite this query to make it without subqueries.

2
  • Why you need them with out the inner query? Nov 26, 2018 at 11:47
  • I'm only studying and I have such kind task Nov 26, 2018 at 12:04

2 Answers 2

1

You can do this in one query with an Aggregate Query:

List<Vacancy__c> ids = new List<Vacancy__c>();

for(AggregateResult result : [
            SELECT Application_Process__r.Vacancy__r.Id Id, 
            Application_Process__r.Vacancy__r.Name Name, 
            Application_Process__r.Vacancy__r.Status__c Status__c, 
            Application_Process__r.Vacancy__r.Requirements__c Requirements__c, 
            Application_Process__r.Vacancy__r.Priority__c Priority__c, 
            Application_Process__r.Vacancy__r.Rate__c Rate__c
            FROM Interview__c
                    WHERE NOT(Meeting_Date__c = LAST_N_DAYS:7
                    OR Meeting_Date__c > TODAY) AND Application_Process__r.Status__c = 'Open' 
            GROUP BY 
            Application_Process__r.Vacancy__r.Id, 
            Application_Process__r.Vacancy__r.Name, 
            Application_Process__r.Vacancy__r.Status__c, 
            Application_Process__r.Vacancy__r.Requirements__c, 
            Application_Process__r.Vacancy__r.Priority__c, 
            Application_Process__r.Vacancy__r.Rate__c
]) {
        ids.add(result.get('Id'));
}
0

I have no idea why you would need to do this, but I would first query the Interview-records you need and create a Set of Ids.

Then you can use the Set instead of the subquery.

0

You must log in to answer this question.

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