1

in my this code--

public class ClosingCaseOnClosingInvoice
{

  public static void CloseCase(List<Invoice__c> invoiceList)
  {
      List<CaseInvoice__c> caseList = [Select Case__c from CaseInvoice__c 
                                        where Invoice__c IN: invoiceList];  


  }
}

i know i can sort this out by using this-

List<CaseInvoice__c> caseList = [Select Case__c 
                                   from CaseInvoice__c 
                                  where Invoice__c =: invoiceList[0].id];  

bt i want to write bulkified code which will be able to deal with multiple records at a time. Can someone please help me out.

1
  • Is the closeCase method being called inside a for loop? You need to add more details on how this method is being invoked?
    – Sam
    Mar 14, 2016 at 6:18

1 Answer 1

1

Actually in your class You are quering CaseInvoice__c and assignning to Case object.

You need to assign to CaseInvoice__c instead case

 List<CaseInvoice__c> lstCaseInvoice= [Select Case__c 
                                         from CaseInvoice__c 
                                        where Invoice__c IN: invoiceList];  

FYI: change your title looks like you are asking for code to bulkify.. it is bit confusing.


Updates

Short way

You can just query simply

 where Invoice__c IN: invoiceList

else another

long way

first collect all the Invoice Ids in set and then perform query on Case Invoice

set<Id> setInvoiceIds = new set<Id>();
for(Invoice__c objInvoice: invoiceList){
setInvoiceIds.add(objInvoice.Id);
}
List<CaseInvoice__c> caseList = [Select Case__c 
                                   from CaseInvoice__c 
                                  where Invoice__c IN: setInvoiceIds];  
7
  • ya actually i have corrected that but forgot to correct it here
    – Sharma_raj
    Mar 14, 2016 at 6:09
  • now please can you help me out to make this code as bulkified code so that i can be able to deal multiple records
    – Sharma_raj
    Mar 14, 2016 at 6:11
  • @RAT__ I can't see your complete code. I can see only 3 lines of code... how should I make 3 lines of code bulkify?
    – Ratan Paul
    Mar 14, 2016 at 6:13
  • actually i just want an idea how to pass multiple id of invoicelist.List<CaseInvoice__c> caseList = [Select Case__c from CaseInvoice__c where Invoice__c =: invoiceList[0].id]; here i am only passing one invoiceList Id.
    – Sharma_raj
    Mar 14, 2016 at 7:01
  • 1
    @RAT__ check my updated ans.
    – Ratan Paul
    Mar 14, 2016 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.