You need to sign in to do that
Don't have an account?
Cris9931
Can someone help me?
too many sql queries: 101
Hi, I have this simple trigger and I'm not sure which line is causing the problem...:
trigger SIG_Trigger_IT_WO on SVMXC__Service_Order__c (before insert, before update) { Set<Id> srId = new Set<Id>(); List<SVMXC__Service_Request__c> srToUpdate= new List<SVMXC__Service_Request__c>(); for(SVMXC__Service_Order__c wos : Trigger.New){ srId.add(wos.SVMXC__SM_Service_Request__c); } List<SVMXC__Service_Request__c> sr= [select id, Number_of_Open_Work_Orders__c from SVMXC__Service_Request__c where Id in :srId ]; List<SVMXC__Service_Order__c > wos= [select id, SVMXC__Order_Status__c from SVMXC__Service_Order__c where (SVMXC__Order_Status__c != 'Closed' AND SVMXC__Order_Status__c != 'Cancelled') AND SVMXC__SM_Service_Request__c in :srId ]; for(SVMXC__Service_Request__c s : sr){ s.Number_of_Open_Work_Orders__c = wos.size(); srToUpdate.add(s); } update srToUpdate; }
Can someone help me?
https://www.appseconnect.com/recursive-trigger-in-salesforce/#:~:text=The%20Recursive%20trigger%20is%20a,how%20it%20can%20be%20avoided.&text=The%20trigger%20calls%20a%20function%20called%20'Call'.
this helped me. :) seems like it's a reccursive thing.
All Answers
You need to setup debug logs to see the stack trace of SOQL that is throwing this error.
There can be multiple reasons for this exception:
Check if SOQL queries are not written in loops
Check if DML is not called inside a loop.
Check if a large number of workflows for field updates are not created on the same object, if possible, move the field update code to trigger.
In your code, I cannot see SOQL calls inside of loops, so there is a good chance there is a Trigger or Process Flow working on the background which is not "Bulkified", thus causing the limit to be hit.
Related:
https://help.salesforce.com/articleView?id=000331875&type=1&mode=1
https://blog.webnersolutions.com/salesforce-system-limitexception-too-many-soql-queries-101/
Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
Please check this post to avoid limit
I recommend checking how many queries have run so far using the following and optimizing the code
Let me know if this helps
https://www.appseconnect.com/recursive-trigger-in-salesforce/#:~:text=The%20Recursive%20trigger%20is%20a,how%20it%20can%20be%20avoided.&text=The%20trigger%20calls%20a%20function%20called%20'Call'.
this helped me. :) seems like it's a reccursive thing.