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 

delete list of child records from Parent where Unit price=0 and sunsegment='Undefined'

Hi All I am trying to use the below code to delete the Billing Item.
Billing item is having a Master-detail with BillDoc.and also a rollup is there in Billing Doc.
I have written the following code.It is working where we have single Billing Item.but when there are Billing Item with valuesand 
Subsegment!=Undefined .It is not working .
public class DeleteBillingItems
{
    @InvocableMethod
    public static void BIDelete(List<Id> BIIds)
    {
        List<BillingItem__c> BI =[select id,UnitPrice__c,Sub_Segment__c,Gross__c,NettoAmount2__c from BillingItem__c
                          where BillingItem__c.id in :BIIds
                       and UnitPrice__c=0 and Sub_Segment__c='Undefined' and Gross__c=0 and NettoAmount2__c =0 ];
        delete BI;
        }
}

Please suggest.

Thanks
Steven NsubugaSteven Nsubuga
public class DeleteBillingItems
{
    @InvocableMethod
    public static void BIDelete(List<Id> BIIds)
    {
		// Assuming that BillDoc__c is the API Name and that BillDoc__c is the master detail field 
		// and that BIIds is the list of BillDoc__c Ids
        List<BillingItem__c> BI =[select id,UnitPrice__c,Sub_Segment__c,Gross__c,NettoAmount2__c from BillingItem__c
                          where BillDoc__c in :BIIds
                       and UnitPrice__c=0 and Sub_Segment__c='Undefined' and Gross__c=0 and NettoAmount2__c =0 ];
        delete BI;
        }
}

 
Silpi roy 16Silpi roy 16
Hi Steven,
Thanks for quick reply.

My scenario is to delete Billing Item(Child of Billing Doc) where Unit Price=0 and Sunsegment=Undefecords ined.
Billing Item and Billing doc has one to Many relation.so when I am creating any billing item with the mentioned criteria.it is getting deleted nut for existing records getting error.


 
Steven NsubugaSteven Nsubuga
You need to provide more information:
  • What is List<Id> BIIds, is it list of Billing Item Ids or list of Billing Doc Ids?
  • Sub_Segment__c='Undefined'. Are you sure you have records in the system with this criteria?
  • Gross__c and NettoAmount2__c , are these fields on Billing Doc or Billing Item?
Silpi roy 16Silpi roy 16
Hi Steven,

What is List<Id> BIIds, is it list of Billing Item Ids or list of Billing Doc Ids? list of Billing Item
Sub_Segment__c='Undefined'. Are you sure you have records in the system with this criteria?yes
Gross__c and NettoAmount2__c , are these fields on Billing Doc or Billing Item?Fields in Billing Item and rollup is there in Billing doc
Glyn Anderson (Slalom)Glyn Anderson (Slalom)
What error are you getting?