+ Start a Discussion

How to query records which does not have any records in a related object.

I have 2 custom objects


Order Line
Inventory Allocations


Inventory Allocation has a lookup relationship to Order Line


When Order Line is created then it may create inventory allocation records when inventory is available.


So there can be situations where a order line has no inventory allocations.


How can I query the order lines which does not have any inventory allocations.


I need to create a VF page which shows these records and process the records to create new inventory allocations.



Select Name FROM OrderLine__c WHERE InventoryAllocation__c = null 

 Replace with actual object/field names.


this will not work in my case because,  OrderLine is linked to the inventory allocations. So this will not work


Following fields are in the  Inventory Aloocation object



Name  (Auto Seq)

OrderLine__c (Lookup to Order Line)\

Allocation Qty




Do you have master-detail relationship in order line and inventory allocation objects ? if it is then you can create a roll-up summary field in order line which contain count of child records. hope it make sense.


It does not have master detail relationship. it has lookup relationship.


It is an existing managed released object and I can ot change the lookup relationship to master detail.


You can do it in following way :-


[select id, name from account where Id NOT IN (select accountid from contact )   ]


just replace account with order line(parent object) and contact with inventory allocation(child)