• Richard Gilchrist
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi,

I have a trigger written as:
 
trigger UpdateLeadFunnelStage on CampaignMember (after insert)
{
    Set<Id> LeadIds = new Set<ID>();
    for(CampaignMember cm : Trigger.New) {
        LeadIds.add(cm.LeadId);
    }

    List<Lead> leads = [ SELECT Id, Lead_Funnel_Stage__c FROM Lead WHERE Id IN :LeadIds];
    List<Lead> leadsToUpdate = new List<Lead>();

    for(Lead l : leads) 
    {
        if(l.Lead_Funnel_Stage__c == null || l.Lead_Funnel_Stage__c == '')
        {
            l.Lead_Funnel_Stage__c = 'Inquiry';
            leadsToUpdate.add(l);
        }
    }

    Update leadsToUpdate;
}

I am receiving 'Too Many SOQL queries: 101' exceptions. I don't see how that's possible as this is bulkified and should only make one SOQL query per batch. Any ideas?
Hi,

I have a trigger written as:
 
trigger UpdateLeadFunnelStage on CampaignMember (after insert)
{
    Set<Id> LeadIds = new Set<ID>();
    for(CampaignMember cm : Trigger.New) {
        LeadIds.add(cm.LeadId);
    }

    List<Lead> leads = [ SELECT Id, Lead_Funnel_Stage__c FROM Lead WHERE Id IN :LeadIds];
    List<Lead> leadsToUpdate = new List<Lead>();

    for(Lead l : leads) 
    {
        if(l.Lead_Funnel_Stage__c == null || l.Lead_Funnel_Stage__c == '')
        {
            l.Lead_Funnel_Stage__c = 'Inquiry';
            leadsToUpdate.add(l);
        }
    }

    Update leadsToUpdate;
}

I am receiving 'Too Many SOQL queries: 101' exceptions. I don't see how that's possible as this is bulkified and should only make one SOQL query per batch. Any ideas?