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 

I want to check if Unit price has Null value or Unit price = 0 then I want to delete the Billing Item.

Hi All,
I want to check if Unit price has Null value or Unit price = 0 then I want to delete the Billing Item.
For that I have written the below code but getting error
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 || IsNull(UnitPrice__c)=True and  Sub_Segment__c='Undefined' and Gross__c=0 and NettoAmount2__c =0 ];
       
        delete BI;

        }
}
Error:Missing ']' at '||' at line 8 column 43
devedeve
Hi Silpi,

Please try this. I have done some minor change in query

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 || UnitPrice__c=null and  Sub_Segment__c='Undefined' and Gross__c=0 and NettoAmount2__c =0 ];
       
        delete BI;

        }
}
 
Silpi roy 16Silpi roy 16
Hi Deve,

Tried with that also not working
Raj VakatiRaj Vakati
Try this code
 
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 Id IN :BIIds and BillingDocumentId__c!=Null
				   AND( UnitPrice__c=0 || UnitPrice__c=null) and  Sub_Segment__c='Undefined' and Gross__c=0 and NettoAmount2__c =0 ];
   
	delete BI;

	}
}

 
Ajay K DubediAjay K Dubedi
Hi Silpi,

Here is your code with small changes. Hope this will help for you.
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 Id in :BIIds 
                          and BillingDocumentId__c!=Null 
                          and (UnitPrice__c=0 || IsNull(UnitPrice__c)=True)
                          and  Sub_Segment__c='Undefined' 
                          and Gross__c=0 
                          and NettoAmount2__c =0 ];
       
        delete BI;

        }
}

Thank you
Ajay Dubedi
Silpi roy 16Silpi roy 16
Still getting the same error
devedeve
Hi Silpi,

Try this,

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;

        }
}