I have these objects and relationships in my org:
Contract__c >- Account -< IL__c
Where >- and -< mean many-to-one/one-to-many relationships. So Account can have many Contract__c's and many IL__c's. Only one of those Contract__c has an active__c check field set to true.
I need to query IL__c with a where clause comparing IL__c.start__c to a field in Contract__c, but that field varies according to some conditions in that Contract__c.
Contract__c has these date fields:
- start_a__c
- end_a__c
- start_b__c
- end_b__c
If end_a__c is null, I have to query IL__c's where start__c >= Contract__c.start_a__c. Otherwise, I have to query where start__c >= Contract__c.start_b__c. If the "a" period (the one defined by start_a__c and end_a__c) is closed, it doesn't make sense for the process to retrieve those records.
So my idea was to build a Map. Key is the Account id. The value is in instance of SomeClass, which has an instance of the active Contract__c of the Account. And SomeClass has someMethod() which, by examining the Contract__c conditions I previously explained, returns the correct start to compare with. And I intended to use that map like this:
select start__c, end__c
from IL__c
where start__c >= :theMap.get(accountId__c).someMethod()
Being accountId__c the relationship of the IL__c with the Account. It fails to save my class because "variable accountId__c does not exist".
How can I query the exact needed set of IL__c records and nothing else?