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
Silpi roy 16Silpi roy 16 

Data deletion Trigger

I have a requirement:
When the Billing Item with Unit price=0 and Subsegment=Undefined I need to delete the data.
I have written the below code and Process Builder to handle the same but its not working as expected.
public class DeleteBillingItems
{
    @InvocableMethod
    public static void BIDelete(List<Id> BIIds)
    {
        List<BillingItem__c> BI =[select id,BillingDocumentId__c,UnitPrice__c,Sub_Segment__c,Gross__c,NettoAmount2__c from BillingItem__c
                          where BillingItem__c.id in :BIIds and BillingDocumentId__c!=Null
                       and (UnitPrice__c=0 OR UnitPrice__c=null) and  Sub_Segment__c='Undefined' and Gross__c=0 and NettoAmount2__c =0 ];
       
        delete BI;
       
      
        }
}
ProcessBuilder:
If criteria meets calling the apex class.

Please suggest any other workaround
Silpi roy 16Silpi roy 16
PLEASE NOTE THE DATA SOURCE IS FROM SAP
Ravi Dutt SharmaRavi Dutt Sharma
Can you put a debug to check what is returned by your SOQL. I think the list is coming as blank.
public class DeleteBillingItems
{
    @InvocableMethod
    public static void BIDelete(List<Id> BIIds)
    {
        List<BillingItem__c> BI =[select id,BillingDocumentId__c,UnitPrice__c,Sub_Segment__c,Gross__c,NettoAmount2__c from BillingItem__c
                          where BillingItem__c.id in :BIIds and BillingDocumentId__c!=Null
                       and (UnitPrice__c=0 OR UnitPrice__c=null) and  Sub_Segment__c='Undefined' and Gross__c=0 and NettoAmount2__c =0 ];
       
        System.debug('BI: '+BI);
        delete BI;
       
      
        }
}
Silpi roy 16Silpi roy 16
Hi Ravi Dutt Sharma,

Yes it is returning blank .what should be the workaround can u suggest.