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
Khalid AbdullahKhalid Abdullah 

Remove Items from a List Array based on Conditions

My query is as follows:

query = 'SELECT Id' + getEditableFields(Schema.SObjectType.Order_Item__c.fields.getMap().values()) + ' FROM Order_Item__c WHERE Order__c=\'' + controller.getRecord().Id + '\'';
            List<Order_Item__c> lineItems = new List<Order_Item__c>();
            
            for (Order_Item__c li : Database.query(query)) {
                Order_Item__c liClone = new Order_Item__c(
                    Order__c = order.Id
                );
                If (li.Fulfillment_Status__c == 'Active' || li.In_Stock__c == 'Yes') {
                OrderItemNotification = 'One or more items from this order has been removed because it is either: 1. Out of Stock or 2. Inactive. Please make sure your order has all items necessary prior to submitting to fulfillment';
                DeliverErrorMessage = true;
                Order_Item__c removed = liClone.remove(removed);
                }

The error I'm getting is "Variable does not exist: removed" on the "Order_Item__c removed" line.

What I am trying to do is remove any items that meet either of the If statement conditions. Then I'll assign the OrderItemNotification to the updated order via visualforce.

Any help would be appreciated. Thanks!