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.)
Best Answer
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.