I have a weird situation in one of my classes. There are two custom objects and one of the objects holds a reference to the other. I am deleting records from the child objects.
Here is my code.
List<Line_Item__c> lineItems = [SELECT Id, Name FROM Line_Item__c WHERE Contract__c = 'a0g4D000000CbVKQA0']; System.Debug('Before Deleting All Line Items '+ string.valueOf(lineItems.size())); delete lineItems; System.Debug('After Deleting All Line Items '+ string.valueOf(lineItems.size())); System.Debug(lineItems.size());
The issue I am seeing is that the lineItems.size() is returning the same number of records before and after the delete statement. As a result of this, the code doesn't evaluate an if condition correctly. The way I expect this code to work is that the delete should just delete all the records from the line items object that satisfy the selection criteria. Unfortunately that is not happening in my case. The Debug statement is printing the same number before and after.