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

help...Too Many SOQL Queries
hello - I'm hitting a govenor limit with this SOQL query. I can't figure out why it's hitting the limit. Any help would be greatly appreciated.
for(Lead newLds : newLead){
mapOfNewAffinityType.put(newLds.Affinity_Type__c, newLds.LastNameStreetAndZipCode__c);
mapOfNewAffinitySubType.put(newLds.Affinity_Sub_Type__c, newLds.LastNameStreetAndZipCode__c);
}
//Query Affinity Type
List<Affinity__c> affinity = [SELECT Id, Occupation_Code__c, Occupation_Sub_Type_Code__c, Occupation__c,
Occupation_Sub_Type__c FROM Affinity__c
WHERE Occupation_Code__c = :mapOfNewAffinityType.keySet() OR
Occupation_Sub_Type_Code__c = :mapOfNewAffinitySubType.keySet()];
//Affinity maps
Map<String, String> mapAffinityTyp = new Map<String, String>();
Map<String, String> mapAffinitySubTyp = new Map<String, String>();
//Affinity values
for(Affinity__c af : affinity) {
mapAffinityTyp.put(af.Occupation_Code__c, af.Occupation__c);
mapAffinitySubTyp.put(af.Occupation_Sub_Type_Code__c, af.Occupation_Sub_Type__c);
}
for(Lead newLds : newLead){
mapOfNewAffinityType.put(newLds.Affinity_Type__c, newLds.LastNameStreetAndZipCode__c);
mapOfNewAffinitySubType.put(newLds.Affinity_Sub_Type__c, newLds.LastNameStreetAndZipCode__c);
}
//Query Affinity Type
List<Affinity__c> affinity = [SELECT Id, Occupation_Code__c, Occupation_Sub_Type_Code__c, Occupation__c,
Occupation_Sub_Type__c FROM Affinity__c
WHERE Occupation_Code__c = :mapOfNewAffinityType.keySet() OR
Occupation_Sub_Type_Code__c = :mapOfNewAffinitySubType.keySet()];
//Affinity maps
Map<String, String> mapAffinityTyp = new Map<String, String>();
Map<String, String> mapAffinitySubTyp = new Map<String, String>();
//Affinity values
for(Affinity__c af : affinity) {
mapAffinityTyp.put(af.Occupation_Code__c, af.Occupation__c);
mapAffinitySubTyp.put(af.Occupation_Sub_Type_Code__c, af.Occupation_Sub_Type__c);
}
Regards
Andrew
The two things I would try now would be:
1. Strip out one condition in the WHERE statement to see the result.
2. Strip out the other condition in the WHERE statement to see the result
3. With the full WHERE condition, only pull the Id in the SELECT statement.
Apart from that i would need to do a setup in a test environment to investigate.
Regards
Andrew