I have a Aura Component, inside which I'm doing some calculation inside for loop. In the for loop, I'm iterating around 3100 records, which is taking lot of time to process.
Since the event on which this method is called is onchange, I'm not able to give any other value after giving first value.
What other options I have to process this?
Below is my JS Method:
let priceTable = component.get("v.priceTableList");
let tableLength = priceTable.length -1;
for(let i=0;i<tableLength; i++){
if(priceTable[i].Unit__c <= zeroYear.Jan_Grid_kWh__c && priceTable[i].Unit_10__c > zeroYear.Jan_Grid_kWh__c){
zeroYear.Jan_Charges__c = Math.round(priceTable[i].Price__c);
}
if(priceTable[i].Unit__c <= zeroYear.Feb_Grid_kWh__c && priceTable[i].Unit_10__c > zeroYear.Feb_Grid_kWh__c){
zeroYear.Feb_Charges__c = Math.round(priceTable[i].Price__c);
}
if(priceTable[i].Unit__c <= zeroYear.Mar_Grid_kWh__c && priceTable[i].Unit_10__c > zeroYear.Mar_Grid_kWh__c){
zeroYear.Mar_Charges__c = Math.round(priceTable[i].Price__c);
}
if(priceTable[i].Unit__c <= zeroYear.Apr_Grid_kWh__c && priceTable[i].Unit_10__c > zeroYear.Apr_Grid_kWh__c){
zeroYear.Apr_Charges__c = Math.round(priceTable[i].Price__c);
}
if(priceTable[i].Unit__c <= zeroYear.May_Grid_kWh__c && priceTable[i].Unit_10__c > zeroYear.May_Grid_kWh__c){
zeroYear.May_Charges__c = Math.round(priceTable[i].Price__c);
}
if(priceTable[i].Unit__c <= zeroYear.Jun_Grid_kWh__c && priceTable[i].Unit_10__c > zeroYear.Jun_Grid_kWh__c){
zeroYear.Jun_Charges__c = Math.round(priceTable[i].Price__c);
}
if(priceTable[i].Unit__c <= zeroYear.Jul_Grid_kWh__c && priceTable[i].Unit_10__c > zeroYear.Jul_Grid_kWh__c){
zeroYear.Jul_Charges__c = Math.round(priceTable[i].Price__c);
}
if(priceTable[i].Unit__c <= zeroYear.Aug_Grid_kWh__c && priceTable[i].Unit_10__c > zeroYear.Aug_Grid_kWh__c){
zeroYear.Aug_Charges__c = Math.round(priceTable[i].Price__c);
}
if(priceTable[i].Unit__c <= zeroYear.Sep_Grid_kWh__c && priceTable[i].Unit_10__c > zeroYear.Sep_Grid_kWh__c){
zeroYear.Sep_Charges__c = Math.round(priceTable[i].Price__c);
}
if(priceTable[i].Unit__c <= zeroYear.Oct_Grid_kWh__c && priceTable[i].Unit_10__c > zeroYear.Oct_Grid_kWh__c){
zeroYear.Oct_Charges__c = Math.round(priceTable[i].Price__c);
}
if(priceTable[i].Unit__c <= zeroYear.Nov_Grid_kWh__c && priceTable[i].Unit_10__c > zeroYear.Nov_Grid_kWh__c){
zeroYear.Nov_Charges__c = Math.round(priceTable[i].Price__c);
}
if(priceTable[i].Unit__c <= zeroYear.Dec_Grid_kWh__c && priceTable[i].Unit_10__c > zeroYear.Dec_Grid_kWh__c){
zeroYear.Dec_Charges__c = Math.round(priceTable[i].Price__c);
}
//
if(priceTable[i].Unit__c <= accRec.January__c && priceTable[i].Unit_10__c > accRec.January__c){
zeroYear.January_Belco_w_o_solar__c = Math.round(priceTable[i].Price__c);
}
if(priceTable[i].Unit__c <= accRec.February__c && priceTable[i].Unit_10__c > accRec.February__c){
zeroYear.February_Belco_w_o_solar__c = Math.round(priceTable[i].Price__c);
}
if(priceTable[i].Unit__c <= accRec.March__c && priceTable[i].Unit_10__c > accRec.March__c){
zeroYear.March_Belco_w_o_solar__c = Math.round(priceTable[i].Price__c);
}
if(priceTable[i].Unit__c <= accRec.April__c && priceTable[i].Unit_10__c > accRec.April__c){
zeroYear.April_Belco_w_o_solar__c = Math.round(priceTable[i].Price__c);
}
if(priceTable[i].Unit__c <= accRec.May__c && priceTable[i].Unit_10__c > accRec.May__c){
zeroYear.May_Belco_w_o_solar__c = Math.round(priceTable[i].Price__c);
}
if(priceTable[i].Unit__c <= accRec.June__c && priceTable[i].Unit_10__c > accRec.June__c){
zeroYear.June_Belco_w_o_solar__c = Math.round(priceTable[i].Price__c);
}
if(priceTable[i].Unit__c <= accRec.July__c && priceTable[i].Unit_10__c > accRec.July__c){
zeroYear.July_Belco_w_o_solar__c = Math.round(priceTable[i].Price__c);
}
if(priceTable[i].Unit__c <= accRec.August__c && priceTable[i].Unit_10__c > accRec.August__c){
zeroYear.August_Belco_w_o_solar__c = Math.round(priceTable[i].Price__c);
}
if(priceTable[i].Unit__c <= accRec.September__c && priceTable[i].Unit__c > accRec.September__c){
zeroYear.September_Belco_w_o_solar__c = Math.round(priceTable[i].Price__c);
}
if(priceTable[i].Unit__c <= accRec.October__c && priceTable[i].Unit_10__c > accRec.October__c){
zeroYear.October_Belco_w_o_solar__c = Math.round(priceTable[i].Price__c);
}
if(priceTable[i].Unit__c <= accRec.November__c && priceTable[i].Unit_10__c > accRec.November__c){
zeroYear.November_Belco_w_o_solar__c = Math.round(priceTable[i].Price__c);
}
if(priceTable[i].Unit__c <= accRec.December__c && priceTable[i].Unit_10__c > accRec.December__c){
console.log('>>> priceTable[i].Price__c... '+priceTable[i].Price__c);
console.log('>>> priceTable[i].Unit__c... '+priceTable[i].Unit__c);
zeroYear.December_Belco_w_o_solar__c = Math.round(priceTable[i].Price__c);
}
}