When I update records in SFDC using dataloader, it executes my trigger and I'm getting a System.LimitException: Too many SOQL queries: 101. I am now changing my trigger so that I don't make any SOQL calls in the FOR loop. Problem is, how can I get the oldMap and NewMap of the Opportunity outside the for loop? Because the for loop is creating the variable "opp" which I need to reference to get the old map. How can i do this outside the for loop? I've tried looking for syntax but haven't found anything. Thanks in advance for the help.
trigger TestTrigger on Opportunity (before update) {
Opportunity oldOpportunity = Trigger.oldMap.get(opp.ID);
for(Opportunity opp : Trigger.new){
...
oppOwnerId = [SELECT Id FROM User WHERE Id=:oldOpportunity.OwnerId limit 1];
...
}
}