You need to sign in to do that
Don't have an account?
Too many SOQL queries
I think the issue is the SOQL in the for statement, but I'm having issues trying to put this kind of SOQL Count in a map. I'm assuming some sort of mapping is required to get around my too many queries issue.
Can someone please point me in the right direction?
trigger StarRatingCampaign on CampaignMember (after insert)
{
Set<Id> leadId = new Set<Id>();
for (CampaignMember cm : trigger.new){leadId.add(cm.CampaignId);
Integer i = [SELECT count() FROM CampaignMember where CampaignId != '701C0000000ZFdA' and CampaignId=:Leadid and (Star_RatingF__c = '5' OR Star_RatingF__c = '4')];
Campaign newCampaign = new Campaign(id=cm.campaignid, Total_5_4_Star_Leads__c = i );
update newCampaign;}
}
I was kinda working on that today. I attempted to make an aggregate query map that passes the id of an object as a map key, and the count as the map value. I wasn't able to get it to work however.
So i decided to create a regular map, and accumulate the total of iterations of that map to get the count.
Pseudo Example:
Hope this helps.
This seems to work, thanks for your help!
This is a greate Site:
http://th3silverlining.com/2009/07/01/how-to-avoid-avoid-governor-limits-part-1-of-n/
It help me a lot.
regards[]