Question d’entretien chez Splunk

public Class QuoteTriggerHandler{ public static void AfterUpdate(List newQuots, Map oldQuote){ Set OrderReady = new Set(); List ordertoUpdate = new List(); for (Quote qte : newQuots) { if(qte.status!=null && qte.status!= oldQuote.get(qte.Id).status && qte.status=='Order Placed'){ Order o1= new Order(); o1.Quote= qte.id; ordertoUpdate.add(o1); OrderReady.add(qte.id); } } if(!ordertoUpdate.isEmpty()) INSERT as system ordertoUpdate; if(!OrderReady.isEmpty()) processOrderProducts(OrderReady); } @future public static void processOrderProducts(Set quoteIds){ List allOrders =[SELECT Id from Order where Quote in: quoteIds]; List allQuotes =[SELECT Id,(SELECT Id, Startdate, enddate, Quantity from QuoteLines) from Quote where Id in: quoteIds]; Map qteOrderMap= new Map(); for(Order o1: allOrders){ qteOrderMap.put(o1.Quote, o1.id); } List<>OrderProduct> opsToUpdate =new List<>OrderProduct> (); for(Quote quote: allQuotes){ if(!quote.QuoteLines.isEmpty()){ opsToUpdate.addALL(QuoteTriggerHandler.createOrderProducts(quote.QuoteLines);) } } if(!opsToUpdate.isEmpty()) INSERT as system opsToUpdate; } public static List createOrderProducts(List quoteLines){ Map> productQL = new Map> (); for(QuoteLine ql: quoteLines){ if(productQL.containsKey(ql.productName)){ productQL.put(ql.productName, productQL.get(productQL).add(ql)); }else { productQL.put(ql.productName, new List{ql}); } } List<>OrderProduct> ops =new List<>OrderProduct> (); for(String pname: productQL.KeySet()){ list qlines = productQL.get(pname); Date Startdate= qlines[0].Startdate; Date enddate= qlines[0].enddate; Date initialQ =qline[0].Quantity; Date finalQ =qline[0].Quantity; for(Integer i=1; i< qlines.size();i++ ){ if(qlines[i].Startdate < Startdate){ Startdate = qlines[i].Startdate; }else if(lines[i].Startdate = Startdate)){ initialQ +=qline[i].Quantity; } if(qlines[i].enddate > enddate){ enddate = qlines[i].enddate; } finalQ +=qline[i].Quantity; } OrderProduct op =new OrderProduct(); op.Order=qteOrderMap.get(qlines[0].Quote); op.Startdate =Startdate; op.enddate=enddate; op.initialQuantity =initialQ; op.finalQuoantity = finalQ; ops.add(op); } return ops; } }