You need to sign in to do that
Don't have an account?
Lance Brown
Apex Trigger caused an unexpected exception "System.Limit.Exception:Too many SOQL queries:101"
WHat did I do wrong? I'm unable to dataload any changes.
trigger LOC_on_IP on SVMXC__Installed_Product__c (before insert, before update) {
List<SVMXC__Installed_Product__c> locationToUpdate = new List<SVMXC__Installed_Product__c>();
for (SVMXC__Installed_Product__c ip : Trigger.new)
{
if (ip.SVMXC__Company__c != NULL)
{
// Find the Loaction for the current Acct
List<SVMXC__Site__c> loc = [select Loc_ID__c from SVMXC__Site__c
where SVMXC__Account__c = :ip.SVMXC__Company__c limit 1];
// if you found one
if (loc.size() > 0)
{
//assign the Location to the Accounts Location
ip.SVMXC__Site__c = loc[0].Loc_ID__c;
locationToUpdate.add(ip);
}
}
}
}
trigger LOC_on_IP on SVMXC__Installed_Product__c (before insert, before update) {
List<SVMXC__Installed_Product__c> locationToUpdate = new List<SVMXC__Installed_Product__c>();
for (SVMXC__Installed_Product__c ip : Trigger.new)
{
if (ip.SVMXC__Company__c != NULL)
{
// Find the Loaction for the current Acct
List<SVMXC__Site__c> loc = [select Loc_ID__c from SVMXC__Site__c
where SVMXC__Account__c = :ip.SVMXC__Company__c limit 1];
// if you found one
if (loc.size() > 0)
{
//assign the Location to the Accounts Location
ip.SVMXC__Site__c = loc[0].Loc_ID__c;
locationToUpdate.add(ip);
}
}
}
}
This problem is coming because you are using soql in for loop,
Use below code
The goal is to populate a lookup (SVMXC__Site__c) on the Installed Products Object that has a lookup (SVMXC__Company__c) to the Account Page . The Account Page has a lookup to the "SVMXC__Site__c" called (EQU_Location__c). SO I need to get the Id from the Accounts "EQU_Location__c" to the Installed Products "SVMXC__Site__c"
The issue in Ashlekh code is that he is calling 'containsKey' on the map
So replace line 27 with the following and it should resolve your issue:
ip.SVMXC__Site__c = MapOFSite.get(ip.SVMXC__Company__c).Loc_ID__c;