You need to sign in to do that
Don't have an account?

System.LimitException: Too many SOQL queries: 101 Trigger.pullSE: line 5, column 1".
So i have the attached trigger on my case object. When trying to do a mahor upload we received the following errror:
System.LimitException: Too many SOQL queries: 101 Trigger.pullSE: line 5, column 1".
From reading other post it seems that i have to take the select statement out of the for loop. But my issue is that when i try its not pulling the information as it was. I tried <list> and <map> functions and nothing works so i have put it back to normal and now the code works again. Can anyone help me figure the best approach to get rid of the error.
Code:
trigger pullSE on Case (before update, before insert) { for (case t: trigger.new) { try { if (t.SE__c == null) { t.SE__c = [select User__c from Site__c where Id = :t.Site__c].User__c; //t.Site__r.User__c; } } catch (Exception e) { } } }
Thanks....
All Answers
trigger pullSE on Case (before update, before insert) {
Set<id> userids=new Set<id>();
Map<id,string> siteMap=new Map<id,string>();
for (case t: trigger.new) {
try {
if (t.SE__c == null) {
userids.add(t.site__c);
}
}
catch (Exception e) {
}
}
if(userids!=null){
for(site__c s:select id,user__c from site__c where id in:userids){
siteMap.put(s.id,s.user__c);
}
}
for(case t:trigger.new){
t.se__c=sitemap.get(t.site__c);
}
}
Thanks testrest97, but now im getting a save error that reads: Unexpected Token: 'select' - The error is in the section of code below
Should this be in brackets?
Awesome that fixed it. Thanks im going to bulk upload and test the code to see if the error returns.
Thanks for your help the code and fix helped.
HI testrest97,
So the help you gave me was great it fixed the issue i was having with my code for bulk changes and closes. But in doing that i have a new issue. Now when u go to change the SE field and select a new user after selecting save it clears our the field. I think i need an else statement in here somewhere to keep whatever is already there but not sure where as when i try i keep getting errors. could you help.