I am getting this error System.LimitException: Too many SOQL queries: 101 when I run the class bellow. It seems like it is affecting all the triggers linked to NRProducts__c Object(This object has 45,000 records but the SOQL query should only return 7,000 ). I have a SetInterval JQuery function in the VF Page that clicks the a button every 20 seconds. My question is if I am making any mistake in the Classs code, or any ideas why this is happening. Thank you!
this is the whole error message:
System.LimitException: Too many SOQL queries: 101
Error is in expression '{!CreatePlan}' in component <apex:commandButton> in page inventoryamzipa
Trigger.InventoryAdjCountsONProducts: line 4, column 1
This is the class:
public class InventoryAMZAPIController2{
public String Debug{ get; set; }
public InventoryAMZAPI2.CreateInboundShipmentPlanResult NewPlan{ get; set; }
public List<InboundShipmentPlanRequestItem> RemainingItems{ get; set; }
public void CreatePlan(){
Date target_date = date.today();
List<NRProducts__c> details = [SELECT NRName__c, AMZ_Inventory_Update__c, Active__c, isFBA__c FROM NRProducts__c WHERE isFBA__c=true AND Active__c = true AND AMZ_Inventory_Update__c != :target_date LIMIT 10];
Map<String, InboundShipmentPlanRequestItem> itemsMap = new Map<String, InboundShipmentPlanRequestItem>();
if(!details.isEmpty()){
RemainingItems = new List<InboundShipmentPlanRequestItem>();
for(NRProducts__c rl : details){
InboundShipmentPlanRequestItem item = new InboundShipmentPlanRequestItem(rl.NRName__c);
itemsMap.put(rl.NRName__c, item);
RemainingItems.add(item);
}
//request values
NewPlan = InventoryAMZAPI2.CreateInboundShipmentPlan(
RemainingItems,
'Basic'
);
Map<String, String> soDetailSkuMap = new Map<String, String>();
for(InventoryAMZAPI2.InboundShipmentPlan p : NewPlan.InboundShipmentPlans){
soDetailSkuMap.put(p.SellerSKU, p.InStockSupplyQuantity );
}
//Assign values to products
List<NRPRoducts__c> nr = [Select NRName__c FROM NRProducts__c Where NRName__c IN: soDetailSkuMap.keySet()];
for(NRPRoducts__c detail : nr){
detail.AMZ_Inventory__c = soDetailSkuMap.get(detail.NRName__c );
detail.AMZ_Inventory_Update__c= date.today();
update detail;
}
} else{
Debug = 'Done';
}
}
public class InboundShipmentPlanRequestItem extends InventoryAMZAPI2.InboundShipmentPlanRequestItem{
public InboundShipmentPlanRequestItem(String sellerSKU){
super(sellerSKU);
}
}
}