• Brian Cersosimo
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies

I need to query Contacts that their last opportunity is between a range of dates and the  
Customer_group__c INCLUDES ('SMS MARKETING OPT-IN') 
 
 Opportunities has Customer__c to refer Contacts and CloseDate to check the opp date. 
 
 The problem is that when I try to query something like this, the query takes in mind all opportunities instead of the last one , and I need to use it on a Batch Class so  
Database.getQueryLocator() won't allow me to use aggregate functions on in the query.  

Thank you!

Tables:

Opportunity
+----------------------------+---------------+
|      Customer__c        | CloseDate |
+----------------------------+---------------+
| This is the contact Id |      Date      |
+----------------------------+---------------+

Contact
+----------------------------+-----------------------------------------------------+
|          Id                      |                  Customer_group__c                  |
+----------------------------+-----------------------------------------------------+
| This is the contact Id | Picklist (needs to filter by 'SMS MARKETING OPT-IN' |
+----------------------------+-----------------------------------------------------+