Write a SOQL query to find active Service Resources that have no appointments scheduled tomorrow.
Answer
Use an anti-join: select active resources whose Id is not in the set of resources assigned to appointments tomorrow.
soql
SELECT Id, Name
FROM ServiceResource
WHERE IsActive = true
AND Id NOT IN (
SELECT ServiceResourceId
FROM AssignedResource
WHERE ServiceAppointment.SchedStartTime = TOMORROW
)
Why it works
- The subquery returns the Ids of resources that already have work tomorrow.
NOT INkeeps everyone else, which gives the available technicians.- Filtering on a parent field (
ServiceAppointment.SchedStartTime) inside the subquery is allowed.
A dispatcher can use this list to find who can take extra jobs, or feed it into Fill-In Schedule.
SOQLAnti-JoinService Resource