• Olver_Bassov
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 5
    Replies
Hi I'm having the error on my trigger

CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY:CreateOppForNewSubTriggger: System.LimitException: Too many SOQL queries: 101:--

The trigger is 
 
trigger ZuoraModoProductUpdate on Zuora__SubscriptionProductCharge__c (before insert, before update) {

    Set<Id> zsub_ids = new Set<Id>();
    for(Zuora__SubscriptionProductCharge__c zspc: trigger.new)
    {
        zsub_ids.add(zspc.Zuora__Subscription__c);
    }
    
    List<Zuora__Subscription__c> zsubs = [SELECT Id, Opportunity__c FROM Zuora__Subscription__c WHERE Id IN :zsub_ids];
    
    Map<Id, Zuora__Subscription__c> id_zsubs = new Map<Id, Zuora__Subscription__c>();
    Set<Id> opp_ids = new Set<Id>();
    for(Zuora__Subscription__c zsub : zsubs)
    {
        id_zsubs.put(zsub.Id, zsub);
        opp_ids.add(zsub.Opportunity__c);
    }
    
    List<Opportunity> opps = [SELECT Id, Modo_Web__c FROM Opportunity WHERE Id IN :opp_ids];
    
    Map<Id, Opportunity> id_opps = new Map<Id, Opportunity>();
    for(Opportunity opp : opps)
    {
        id_opps.put(opp.Id, opp);
    }
    
    List<Opportunity> update_opps = new List<Opportunity>();

    for(Zuora__SubscriptionProductCharge__c zspc: trigger.new)
    {
        if(zspc.Zuora__ProductName__c != null && zspc.Zuora__ProductName__c.toLowerCase().contains('modo')) 
        {
            if(zspc.Zuora__Subscription__c != null)
            {
                Zuora__Subscription__c zsub = id_zsubs.get(zspc.Zuora__Subscription__c);
                if(zsub.Opportunity__c != null)
                {
                    Opportunity opp = id_opps.get(zsub.Opportunity__c);
                    opp.Modo_Web__c = true;
                    update_opps.add(opp);
                }
            }
        }
    }
    update update_opps;
}

I believe it's something in the for loop but I can't finde where if someone could give me a light it will be much appreciated.

Thanks in advance.
 
I have the following validation rule to forbid users altering the close date (field) of the opportunity before the 4th day of the current month although I got a problem because is not taking the desired effect.

The Formula I'm using is:
 
AND(ISCHANGED( CloseDate ),
IF(AND(TODAY() <= DATEVALUE 
(TEXT (Year (Today())) & '-' & TEXT (Month (Today())) & '-' & '04'),
MONTH (CloseDate) < MONTH (TODAY ()) -1)
,TRUE,IF(AND(TODAY() > DATEVALUE 
(TEXT (Year (Today())) & '-' & TEXT (Month (Today())) & '-' & '04'),
 CloseDate < DATEVALUE (TEXT (Year (Today())) & '-' & TEXT (Month (Today())) & '-' & '01')),TRUE,FALSE)))




Can someone with more knowledge than me give me  some light ? It will be much appreciatted 

Thank you

I'm getting this error on my Trigger. 

I believe the part of the code that is causing this is:

public static void ProcessScheduledMaintenanceEmailsTrigger(
            List<Scheduled_Maintenance_Email__c> sched_new,
            List<Scheduled_Maintenance_Email__c> sched_old) {
    
        for (integer i = 0; i < sched_new.size(); i++) {
            if (sched_new[i].Email_Triggered__c == true && sched_old[i].Email_Triggered__c == false) {
                // To send the email, change the state to the scheduled renewal state, which
                // will cause the opportunityAutoRenewalStateChangedTrigger to fire, which
                // in turn will call SendOrScheduleEmail() below
                List<Opportunity> opps = [  SELECT
                                                Id,
                                                Auto_Renewal_State__c
                                            FROM
                                                Opportunity
                                            WHERE
                                                Id= :sched_new[i].Opportunity__c
                ];


If someone knows how to fix this it will be much appreciatted. I have been googling about it but haven't understood how I'd take the select out of the loop.

Thank you

I have the following validation rule to forbid users altering the close date (field) of the opportunity before the 4th day of the current month although I got a problem because is not taking the desired effect.

The Formula I'm using is:
 
AND(ISCHANGED( CloseDate ),
IF(AND(TODAY() <= DATEVALUE 
(TEXT (Year (Today())) & '-' & TEXT (Month (Today())) & '-' & '04'),
MONTH (CloseDate) < MONTH (TODAY ()) -1)
,TRUE,IF(AND(TODAY() > DATEVALUE 
(TEXT (Year (Today())) & '-' & TEXT (Month (Today())) & '-' & '04'),
 CloseDate < DATEVALUE (TEXT (Year (Today())) & '-' & TEXT (Month (Today())) & '-' & '01')),TRUE,FALSE)))




Can someone with more knowledge than me give me  some light ? It will be much appreciatted 

Thank you
Hi I'm having the error on my trigger

CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY:CreateOppForNewSubTriggger: System.LimitException: Too many SOQL queries: 101:--

The trigger is 
 
trigger ZuoraModoProductUpdate on Zuora__SubscriptionProductCharge__c (before insert, before update) {

    Set<Id> zsub_ids = new Set<Id>();
    for(Zuora__SubscriptionProductCharge__c zspc: trigger.new)
    {
        zsub_ids.add(zspc.Zuora__Subscription__c);
    }
    
    List<Zuora__Subscription__c> zsubs = [SELECT Id, Opportunity__c FROM Zuora__Subscription__c WHERE Id IN :zsub_ids];
    
    Map<Id, Zuora__Subscription__c> id_zsubs = new Map<Id, Zuora__Subscription__c>();
    Set<Id> opp_ids = new Set<Id>();
    for(Zuora__Subscription__c zsub : zsubs)
    {
        id_zsubs.put(zsub.Id, zsub);
        opp_ids.add(zsub.Opportunity__c);
    }
    
    List<Opportunity> opps = [SELECT Id, Modo_Web__c FROM Opportunity WHERE Id IN :opp_ids];
    
    Map<Id, Opportunity> id_opps = new Map<Id, Opportunity>();
    for(Opportunity opp : opps)
    {
        id_opps.put(opp.Id, opp);
    }
    
    List<Opportunity> update_opps = new List<Opportunity>();

    for(Zuora__SubscriptionProductCharge__c zspc: trigger.new)
    {
        if(zspc.Zuora__ProductName__c != null && zspc.Zuora__ProductName__c.toLowerCase().contains('modo')) 
        {
            if(zspc.Zuora__Subscription__c != null)
            {
                Zuora__Subscription__c zsub = id_zsubs.get(zspc.Zuora__Subscription__c);
                if(zsub.Opportunity__c != null)
                {
                    Opportunity opp = id_opps.get(zsub.Opportunity__c);
                    opp.Modo_Web__c = true;
                    update_opps.add(opp);
                }
            }
        }
    }
    update update_opps;
}

I believe it's something in the for loop but I can't finde where if someone could give me a light it will be much appreciated.

Thanks in advance.
 
I have the following validation rule to forbid users altering the close date (field) of the opportunity before the 4th day of the current month although I got a problem because is not taking the desired effect.

The Formula I'm using is:
 
AND(ISCHANGED( CloseDate ),
IF(AND(TODAY() <= DATEVALUE 
(TEXT (Year (Today())) & '-' & TEXT (Month (Today())) & '-' & '04'),
MONTH (CloseDate) < MONTH (TODAY ()) -1)
,TRUE,IF(AND(TODAY() > DATEVALUE 
(TEXT (Year (Today())) & '-' & TEXT (Month (Today())) & '-' & '04'),
 CloseDate < DATEVALUE (TEXT (Year (Today())) & '-' & TEXT (Month (Today())) & '-' & '01')),TRUE,FALSE)))




Can someone with more knowledge than me give me  some light ? It will be much appreciatted 

Thank you

I'm getting this error on my Trigger. 

I believe the part of the code that is causing this is:

public static void ProcessScheduledMaintenanceEmailsTrigger(
            List<Scheduled_Maintenance_Email__c> sched_new,
            List<Scheduled_Maintenance_Email__c> sched_old) {
    
        for (integer i = 0; i < sched_new.size(); i++) {
            if (sched_new[i].Email_Triggered__c == true && sched_old[i].Email_Triggered__c == false) {
                // To send the email, change the state to the scheduled renewal state, which
                // will cause the opportunityAutoRenewalStateChangedTrigger to fire, which
                // in turn will call SendOrScheduleEmail() below
                List<Opportunity> opps = [  SELECT
                                                Id,
                                                Auto_Renewal_State__c
                                            FROM
                                                Opportunity
                                            WHERE
                                                Id= :sched_new[i].Opportunity__c
                ];


If someone knows how to fix this it will be much appreciatted. I have been googling about it but haven't understood how I'd take the select out of the loop.

Thank you