• Ruben E.
  • NEWBIE
  • 0 Points
  • Member since 2015
  • Huron Consulting Group

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Hello everybody, I have the class below getting data from a trigger (that seems to be working ok), the problem is, I am getting a "Too many SOQL queries" errors when it executes.  If I comment out "insert opptsToInsert;" then I have no problems, but of course my new opportunity is not created.  I've tryied and regarless of where I put the insert I always get the same error. Any suggestions will be welcome.

Thanks


public class RenewalOpportunities 
{
    public void CreateRenewalOpportunity(Map < Id, Opportunity > oldMap, Map < Id, Opportunity > newMap) 
    {
        System.debug('Renewal starting');    
        List < Opportunity > opptsToInsert = new List < Opportunity > ();
        Opportunity newOppt = new Opportunity();
        //List < Id > OpptyIds = new List < Id > ();
        for (Opportunity o: newMap.Values()) 
        {
            //OpptyIds.add(o.id);
            System.debug('Old ID ' + o.id);
            System.debug('Renewal check ' + o.RenewalCreated__c);

            {
                newOppt.Name = o.Name + ' Renewal Opportunity';
                newOppt.AccountId = o.AccountId;
                newOppt.RecordTypeId = o.RecordTypeId;
                newOppt.CloseDate = Date.Today() + 30;
                newOppt.StageName = 'Renewal Opportunity';
                newOppt.Type = 'Add-On Business';
                newOppt.NextStep = 'Send a invoice for maintenance renewal';
                 newOppt.OwnerId =o.OwnerId;}
                opptsToInsert.add(newOppt);
                System.debug('Account Name ' + newOppt.AccountId);
                System.debug('Opportunity Name ' + newOppt.Name);
                System.debug('Stage Name ' + newOppt.StageName);
                System.debug('Type Name ' + newOppt.Type);
                System.debug('Next Step ' + newOppt.NextStep);
                System.debug('Close Date ' + newOppt.CloseDate);
                System.debug('New Opportunities ' + opptsToInsert);
     

        }   
        
        System.debug('Size ' + opptsToInsert.size());
         if (opptsToInsert.size() > 0){ 
            insert opptsToInsert;}
    }
}