function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nick ValerioteNick Valeriote 

SOQL query based on two custom, related objects

Hi SF Community,

Sr. Mngt. has requested the following from me:

- We want to know what clients have projects that have billable-qualified timesheets this fiscal year, but no invoices.  This means that the we did billable work (timesheets) for a client, but have never invoiced them.  This last part is important, because in the query we run, we want to ensure that there have never been any invoices for a client this fiscal year (not to be confused with a client that has invoices for some projects, but no invoices for other projects).

I figure I can gleen this data from running a Projects with Timesheets custom report type, and add some filters.  The only issue is that because we have so many timesheet (timesheet_c) records per month, I can't run a report going back to the start of our fiscal year (Sept 1/18), as it will just timeout.  I would have to run a report on a monthly basis and export it to Excel and match the data by project for each month, and on and on.  I was hoping to accomplish this request with a SOQL query, but I only know the very basics of SOQL (i.e. query one object).  Wondering if someone can help?

The relationship -
Timesheet_c has a lookup field to Project_c (timesheet is child, project is parent).

The query - 
- All projects (Project_c object) created > 2018-08-31T00:00:40.000Z
AND
- Type__c (from Timesheet_c object) not equal to "Business Development, CS - Troubleshooting, Internal Admin, Invoicing, Training & Education - Self, Training & Education - Team"
AND
- Status__c (from Timesheet_c object) equals "Not Invoiced"
AND
- Invoice__c (from Timesheet_c object) equal "" (blank).   

I just want to make sure that the only clients that show up in this query are ones that have never had an invoice logged against any of their projects that meet the above filter criteria.  If they have some projects that were invoiced, and some that were not, I don't want to see them in this query.

Help?
Thanks!
Nick