Following is my trigger I get the following error
System.LimitException: Too Many SOQL Queries: 101 in Trigger
Here is my trigger
trigger SubscriberUpdateTrigger on Subscriber__c (after Insert, after Update, after undelete) {
Set<sfcloud__Product_Bundle__c> listBundleToUpdate = new Set<sfcloud__Product_Bundle__c>();
sfcloud__Product_Bundle__c pb = new sfcloud__Product_Bundle__c();
List<Subscriber__c> subsList = [select id,Subscriber__c.Product_Bundle__c,Active_Subscriber__c,Subscriber_Price_Book__r.id,Subscriber_Price_Book__c,Subscriber_Contact__r.Id,Subscriber_Contact__r.Is_Subscriber__c from Subscriber__c where id IN :Trigger.newMap.keySet()];
for(Subscriber__c ss : subsList)
{
if(ss.Product_Bundle__c != null){
sfcloud__Product_Bundle__c spb = [Select id,Vision__c,Telemedicine__c,Dental__c, Fulfillment__c, name, sfcloud__Price_Book__c,sfcloud__Price_Book__r.id from sfcloud__Product_Bundle__c where id =: ss.Product_Bundle__c];
System.debug('Total Bundle :'+spb);
List<PricebookEntry> pbe = [Select Id, Name, ProductCode, Product2Id, UnitPrice From PricebookEntry where Pricebook2Id =: spb.sfcloud__Price_Book__c];
System.debug('Total PriceEntry:'+pbe.size());
for(PricebookEntry pbe1 : pbe){
if(pbe1.ProductCode == 'Fulfillment'){
pb.Id = spb.Id;
pb.Fulfillment__c = True;
}
if(pbe1.ProductCode == 'Discount_Vision'){
pb.Id = spb.Id;
pb.Vision__c = True;
}
if(pbe1.ProductCode == 'Discount_Dental'){
pb.Id = spb.Id;
pb.Dental__c = True;
}
if(pbe1.ProductCode == 'Telemed_Standard'){
pb.Id = spb.Id;
pb.Telemedicine__c = True;
}
}
listBundleToUpdate.add(pb);
}
System.debug('List'+listBundleToUpdate);
if(!listBundleToUpdate.isEmpty()){
List<sfcloud__Product_Bundle__c> subs = new List<sfcloud__Product_Bundle__c>(listBundleToUpdate);
UPDATE subs;
}
}
}
Thanks, Vimal