+ Start a Discussion
Khalid AbdullahKhalid Abdullah 

Need help removing items from a SOQL Query

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.