Skip to main content
hema priya (.qr) ha fatto una domanda in #Apex
 List <peer__Investment_Booking__c> TEMPInvestmentBookingList = new List<peer__Investment_Booking__c>();

            peer__Investment_Booking__c TEMPInvestmentBooking1;

            bookingOrderList = [SELECT Id, peer__Investor__c,Insured_Amount__c,Total_Insured_Amount__c FROM peer__Booking_Order__c WHERE peer__Investor__c =: account.Id];

              /*List<Id> bookingId = new List<Id>();

            for(peer__Booking_Order__c tempbookingOrder:bookingOrderList){

                 bookingId.add(tempbookingOrder.Id);               

            }

            investmentBookingList = [SELECT peer__Investment_Amount__c,Insured_Percentage__c,Insured_Amount__c,Premium_Component__c,peer__Loan_Application__c

                                         FROM peer__Investment_Booking__c WHERE peer__Booking_Order__c IN :bookingId];

            for(j=0;j<investmentBookingList.size();j++)

                {

                    investmentBooking = investmentBookingList.get(j);

                    TEMPInvestmentBookingList.add(investmentBooking);

                }*/

          for(i=0;i<bookingOrderList.size();i++)

            {

                bookingOrder = bookingOrderList.get(i);

                investmentBookingList = [SELECT peer__Investment_Amount__c,Insured_Percentage__c,Insured_Amount__c,Premium_Component__c,peer__Loan_Application__c

                                         FROM peer__Investment_Booking__c WHERE peer__Booking_Order__c =: bookingOrder.Id];

                for(j=0;j<investmentBookingList.size();j++)

                {

                    investmentBooking = investmentBookingList.get(j);

                    TEMPInvestmentBookingList.add(investmentBooking);

                }

            }

            for(i=0;i<TEMPInvestmentBookingList.size();i++)

            {

                investmentBooking = TEMPInvestmentBookingList.get(i);

                j=i+1;

                while(j<TEMPInvestmentBookingList.size())

                {

                    TEMPInvestmentBooking1 = TEMPInvestmentBookingList.get(j);

                    if(investmentBooking.peer__Loan_Application__c == TEMPInvestmentBooking1.peer__Loan_Application__c)

                    {

                        investmentBooking.peer__Investment_Amount__c = investmentBooking.peer__Investment_Amount__c + TEMPInvestmentBooking1.peer__Investment_Amount__c;

                        TEMPInvestmentBookingList.remove(j);

                    }

                    else{

                        j++;

                    }

                }

            }
3 risposte
  1. 22 dic 2016, 08:34
    Hi Gyan,

    I have udpated your code :

     

    List <peer__Investment_Booking__c> TEMPInvestmentBookingList = new List<peer__Investment_Booking__c>();

    peer__Investment_Booking__c TEMPInvestmentBooking1;

    bookingOrderList = [SELECT Id, peer__Investor__c,Insured_Amount__c,Total_Insured_Amount__c FROM peer__Booking_Order__c WHERE peer__Investor__c =: account.Id];

    /*List<Id> bookingId = new List<Id>();

    for(peer__Booking_Order__c tempbookingOrder:bookingOrderList){

    bookingId.add(tempbookingOrder.Id);

    }

    investmentBookingList = [SELECT peer__Investment_Amount__c,Insured_Percentage__c,Insured_Amount__c,Premium_Component__c,peer__Loan_Application__c

    FROM peer__Investment_Booking__c WHERE peer__Booking_Order__c IN :bookingId];

    for(j=0;j<investmentBookingList.size();j++)

    {

    investmentBooking = investmentBookingList.get(j);

    TEMPInvestmentBookingList.add(investmentBooking);

    }*/

    Map<String,List<peer__Investment_Booking__c>> mapBookingOrder = new Map<String,List<peer__Investment_Booking__c>>();

    for(peer__Investment_Booking__c peer : [SELECT peer__Investment_Amount__c,Insured_Percentage__c,Insured_Amount__c,Premium_Component__c,peer__Loan_Application__c

    FROM peer__Investment_Booking__c WHERE peer__Booking_Order__c in: bookingOrderList]) {

    if(!mapBookingOrder.contains(peer.peer__Booking_Order__c)) {

    mapBookingOrder.put(peer.peer__Booking_Order__c,new List<peer__Investment_Booking__c>);

    }

    mapBookingOrder.get(peer.peer__Booking_Order__c).add(peer);

    }

    for(i=0;i<bookingOrderList.size();i++)

    {

    bookingOrder = bookingOrderList.get(i);

    investmentBookingList = mapBookingOrder.get(bookingOrder.Id);//[SELECT peer__Investment_Amount__c,Insured_Percentage__c,Insured_Amount__c,Premium_Component__c,peer__Loan_Application__c

    // FROM peer__Investment_Booking__c WHERE peer__Booking_Order__c =: bookingOrder.Id];

    for(j=0;j<investmentBookingList.size();j++)

    {

    investmentBooking = investmentBookingList.get(j);

    TEMPInvestmentBookingList.add(investmentBooking);

    }

    }

    for(i=0;i<TEMPInvestmentBookingList.size();i++)

    {

    investmentBooking = TEMPInvestmentBookingList.get(i);

    j=i+1;

    while(j<TEMPInvestmentBookingList.size())

    {

    TEMPInvestmentBooking1 = TEMPInvestmentBookingList.get(j);

    if(investmentBooking.peer__Loan_Application__c == TEMPInvestmentBooking1.peer__Loan_Application__c)

    {

    investmentBooking.peer__Investment_Amount__c = investmentBooking.peer__Investment_Amount__c + TEMPInvestmentBooking1.peer__Investment_Amount__c;

    TEMPInvestmentBookingList.remove(j);

    }

    else{

    j++;

    }

    }

    }