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
pp11222pp11222 

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.

 

thanks

jeremyyjeremyy
Select Name FROM OrderLine__c WHERE InventoryAllocation__c = null 

 Replace with actual object/field names.

pp11222pp11222

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

 

Id

Name  (Auto Seq)

OrderLine__c (Lookup to Order Line)\

Allocation Qty

 

 

hemantgarghemantgarg

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.

pp11222pp11222

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.

hemantgarghemantgarg

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)