Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have a requirement to change the status of any Contact (master object) that has had a Booking (detail object) but not in the last 2 years to "Inactive":

Date d = Date.today().addYears(-2);
Contact[] contacts = [
        select Id
        from Contact
        where Status__c != 'Inactive'
        and Id in (select Client__c from Booking__c)
        and Id not in (select Client__c from Booking__c where LatestBookedDate__c > :d)
        ];

The org will have about 2,000 Contact objects but will end up with more than 50,000 Booking objects. In the content of the above code, I am wondering how this governor limit applies:

Total number of records retrieved by SOQL queries 50,000

I assume/hope it only applies to the Contact object returned by the query and not to the sub-select Booking queries. (But perhaps SOQL aggregate query limit implies the opposite.) Please clarify if you know.

(I'm not looking for alternative queries here, I'm looking to understand how the governor limit is applied.)

share|improve this question

1 Answer 1

up vote 3 down vote accepted

According to my knowledge Limit of 50k objects applies to each object query returns. So each element is counted as 1- no matter from query or nested query. Although list you used as filters (semi-join)are not returning any data and are not count against this limit.

There is no limit on the number of records matched in a subquery. 
Standard SOQL query limits apply to the main query.
share|improve this answer
    
Thanks. Googled that and its in salesforce.com/us/developer/docs/officetoolkit/Content/… if anyone is interested in the context. –  Keith C Mar 9 at 14:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.