You need to sign in to do that
Don't have an account?
madhu reddy 93
Error: System.LimitException: Too many SOQL queries: 101 Triggers
for(WorkOrderLineItem workLine : [select id, workOrderId from workOrderlineItem where workOrderId IN :WorkOrderIds]){
mapWorkOrderLineItem.put(workLine.workOrderId, workLine);
}
Id ProdId = [select Id, Product2Id, Product2.ProductCode from PriceBookEntry where Name = 'Service Fee' and Id = '01u7F000007Xf5XQAS'].Id;
system.debug('**********Product2Id********* '+ProdId);
List<ProductConsumed> prodConsumedList = new List<ProductConsumed>();
if(Trigger.isupdate && trigger.isafter && firstAfterUpdate)
{
for(ServiceAppointment svc : [select id, status, Actual_Duration_Hours__c,ParentRecordId from ServiceAppointment where id IN :trigger.new]){
if(WorkOrderIds.contains(svc.ParentRecordId) && svc.Status =='Completed'){
system.debug('**********svc1********* '+svc);
mapWorkOrderLineItem.get(svc.ParentRecordId).Asset_Title__c='Service Fee';
system.debug('**********svc2********* '+svc);
ProductConsumed pc = new ProductConsumed();
pc.QuantityConsumed = svc.Actual_Duration_Hours__c;
pc.PricebookEntryId = ProdId;
pc.WorkOrderId=svc.ParentRecordId;
pc.WorkOrderLineItemId=mapWorkOrderLineItem.get(svc.ParentRecordId).id;
prodConsumedList.add(pc);
}
}
system.debug('**********svc3********* ');
update mapWorkOrderLineItem.values();
insert prodConsumedList;
system.debug('**********svc4********* ');
}
mapWorkOrderLineItem.put(workLine.workOrderId, workLine);
}
Id ProdId = [select Id, Product2Id, Product2.ProductCode from PriceBookEntry where Name = 'Service Fee' and Id = '01u7F000007Xf5XQAS'].Id;
system.debug('**********Product2Id********* '+ProdId);
List<ProductConsumed> prodConsumedList = new List<ProductConsumed>();
if(Trigger.isupdate && trigger.isafter && firstAfterUpdate)
{
for(ServiceAppointment svc : [select id, status, Actual_Duration_Hours__c,ParentRecordId from ServiceAppointment where id IN :trigger.new]){
if(WorkOrderIds.contains(svc.ParentRecordId) && svc.Status =='Completed'){
system.debug('**********svc1********* '+svc);
mapWorkOrderLineItem.get(svc.ParentRecordId).Asset_Title__c='Service Fee';
system.debug('**********svc2********* '+svc);
ProductConsumed pc = new ProductConsumed();
pc.QuantityConsumed = svc.Actual_Duration_Hours__c;
pc.PricebookEntryId = ProdId;
pc.WorkOrderId=svc.ParentRecordId;
pc.WorkOrderLineItemId=mapWorkOrderLineItem.get(svc.ParentRecordId).id;
prodConsumedList.add(pc);
}
}
system.debug('**********svc3********* ');
update mapWorkOrderLineItem.values();
insert prodConsumedList;
system.debug('**********svc4********* ');
}
That chunk of code looks ok structurally. i.e. no SQL queries in FOR loops.
Are you able to post the full trigger and/or handler to help troubleshoot?
As an aside, i'm surprised that your query works. My understanding is that trigger.new is a list of Objects (related to the trigger) and that matching the Id against a list of objects would not work.
Something like below, may work better. trigger.map.keySet() will provide a List of Ids for the records invoking the trigger.
Regards
Andrew
Hi Andrew Please check above code thanks for advance for helping
Thanks for the full code. Its interesting that you have a Trigger Handler class, but don't seem to be invoking it in the trigger.
Anyway, reading the code, the only thing is that as noted yesterday, the SELECT statement using a list of objects.
Try adjusting the code as follows:
Regards
Andrew