• Will Foley
  • NEWBIE
  • 15 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
This issue came up without any new code being deployed. 

All help is greatly appreciated.

Description of Trigger

The Trigger automatically greats a renewal opportunity after a new opportunity is marked as closed one. 

Code
 
trigger RenewalOpptTrigger on Opportunity (after update) {
    Map<Id, Account> accts = new Map<Id, Account>([SELECT Id, Name FROM Account]);
    List<Opportunity> opps = new List<Opportunity>([SELECT Name FROM Opportunity]);
   //Checking paramaters for Renewal Opportunity - Must be Won and Closed, etc.
   
   if (trigger.isUpdate){
   for (Opportunity opp : Trigger.new){
       System.debug('Opportunity: ' + opp.Name + ', Stage: ' + opp.StageName);
              if(opp.StageName == 'Customer - Closed Won'){
                     if(opp.Type == 'Renewal' || opp.Type =='Renewal and Expansion' || opp.Type == 'New - Enterprise' || opp.Type == 'New Business Expansion'){
                      System.debug(LoggingLevel.Error, 'Opp ID: ' + opp.Id);
                    
                      //Renewal Date Calculations - Renewal Start and End Dates
                      Date contractStartDate = opp.Contract_Start_Date__c;
                      integer duration = (integer)opp.Contract_Duration_Months__c;
                      
                      Date renewalStartDate = contractStartDate.addMonths(duration);
                         system.debug(renewalStartDate);
                           Account acct = accts.get(opp.AccountId);
                           String acctName = acct.Name;
                      
                        String stage = 'SAL Demo Scheduled';
                        decimal amount;
                         
                         if(opp.License__c != null && opp.Contract_Increase__c!=null ){
                         amount =  ((opp.Contract_Increase__c/100)+1) * opp.License__c; 
                        }
                         else{amount = opp.License__c;}
                      
                       
                         system.debug(amount);
               
                      String title = String.valueOf(renewalStartDate.year()) + '_Renewal_' + acctName + '_$' + String.valueOf(amount.format());
                  
                      OpportunityContactRole[] oppconroles = [SELECT IsPrimary, ContactId FROM OpportunityContactRole WHERE OpportunityId = :opp.Id];
                    
                    boolean exists = false;
                    for (Opportunity o : opps) {
                       if (o.Name == title) {
                            exists = true;
                            System.debug(LoggingLevel.Error, o.Name + ' already EXISTS');
                       }
                      }
                    
                         
                         if(!exists){  
                      Opportunity ren_opp = opp.clone(false, true, false, false);
                       ren_opp.License__c = amount;
                       ren_opp.Amount = amount;
                       ren_opp.Previous__c = opp.License__c;
                        system.debug(ren_opp.License__c);
                        ren_opp.StageName = stage;
                        ren_opp.Contract_Start_Date__c = renewalStartDate;
                        ren_opp.Contract_Duration_Months__c = duration;
                        ren_opp.CloseDate = renewalStartDate;
                        ren_opp.Type = 'Renewal';
                        ren_opp.Probability = 10;
                        if(ren_opp.Contract_Increase__c>0){
                                ren_opp.Type='Renewal and Expansion';}
                            
                       
                       ren_opp.Name = title;
                  
                        //System Information deletions
                        ren_opp.CampaignId = null;
                        ren_opp.Date_moved_to_Closed_Lost__c = null;
                        ren_opp.Date_moved_to_Closed_Won__c = null;
                        ren_opp.Date_moved_to_Contract_Sent__c = null;
                        ren_opp.Date_moved_to_Demo_Complete__c = null;
                        ren_opp.Date_moved_to_Demo_Scheduled__c = null;
                        ren_opp.Date_moved_to_Verbal_Commit__c = null;
                        ren_opp.Date_moved_to_Proposal_Sent__c = null;
                        ren_opp.Amount_at_Closed_Lost__c = null;
                        ren_opp.Amount_at_Closed_Won__c = null;
                        ren_opp.Amount_at_Contract_Sent__c = null;
                        ren_opp.Amount_at_Demo_Complete__c = null;
                        ren_opp.Amount_at_Demo_Scheduled__c = null;
                        ren_opp.Amount_at_Proposal_Sent__c = null;
                        ren_opp.Amount_at_Verbal_Commit__c = null;

                        //SOW Deletions
                        ren_opp.Unique_Pricing_Scenario__c = null;
                        ren_opp.Department__c = null;
                        ren_opp.Signature_Events__c = null;
                        ren_opp.Number_of_Seats__c = null;
                        ren_opp.Special_Admin_Structure__c = null;
                        ren_opp.Design_Resources__c = null;
                        ren_opp.Needs_Designer_Pro__c = false;
                        ren_opp.Key_Functionality_Landmines__c = null;
                        ren_opp.Custom_Dev_Work__c=null;
                        ren_opp.Splash_User_Experience__c=null;
                        ren_opp.Kickoff_Email_Recipients__c=null;
                        ren_opp.Imminent_Deadline__c=null;
                        ren_opp.Client_Fears_or_Concerns__c=null;
                        ren_opp.Opportunities_for_Growth__c = null;
                        ren_opp.Opportunities_for_Growth_Yes__c = null;
                        ren_opp.Additional_Comments__c = null;
                        ren_opp.Require_Starter_Themes__c = null;
                       // ren_opp.SOW_End_Date__c = renewalStartDate;
                        
                        ren_opp.Primary_Purpose_of_Events__c = null;

                        //Docusign deletions     
                        ren_opp.DocuSign_Status__c = null;
                    
                        //Discovery Questions deletions   
                        ren_opp.Annual_of_Events__c = null;
                        ren_opp.CRM__c=null;
                        ren_opp.CRM_Other__c=null;
                        ren_opp.CRM_Other__c = null;
                        ren_opp.Budget__c = null;
                        ren_opp.Purpose_of_Events__c = null;
                        ren_opp.Purpose_of_Events_Other__c=null;
                        ren_opp.What_are_they_currently_using__c = null;
                        ren_opp.Marketing_Automation__c = null;
                        ren_opp.Marketing_Automation_Other__c = null;
                        ren_opp.Role_of_Primary_Contact__c = null;
                        ren_opp.Role_of_Primary_Contact_other__c = null;
                        ren_opp.Current_process_for_event_program__c = null;
                        ren_opp.Currently_using_other__c = null;
                        ren_opp.Value_Driver_details__c = null;
                        ren_opp.Primary_Purpose_of_Events_Other__c = null;
                        ren_opp.Need_SPS__c = null;
                  
                        //Other Deletions   
                        ren_opp.ForecastCategoryName = 'Pipeline';
                        ren_opp.Agreed_to_Case_Study__c = false; 
                         
                             insert ren_opp;
                             List<OpportunityContactRole> rolesToInsert = new List<OpportunityContactRole>();
                             for (OpportunityContactRole opprole : oppconroles) {
                            System.debug(LoggingLevel.ERROR, 'ContactRole: ' + opprole.ContactId);
              OpportunityContactRole ocp = opprole.clone(false, true, true, true);
                            ocp.OpportunityId = ren_opp.Id;
                            rolesToInsert.add(ocp);
                        }
                        
                        if (rolesToInsert.size() > 0) {
                            insert rolesToInsert;
                        }
          
                           update ren_opp;
                        
             }                      else{}       
           }            else{
                          System.debug('Case is not of the correct type');
       }    
    }         else{ 
                System.debug('Case '+ opp.Name + ' is not Closed and Won');
   }
  }
 }
}

 
This issue came up without any new code being deployed. 

All help is greatly appreciated.

Description of Trigger

The Trigger automatically greats a renewal opportunity after a new opportunity is marked as closed one. 

Code
 
trigger RenewalOpptTrigger on Opportunity (after update) {
    Map<Id, Account> accts = new Map<Id, Account>([SELECT Id, Name FROM Account]);
    List<Opportunity> opps = new List<Opportunity>([SELECT Name FROM Opportunity]);
   //Checking paramaters for Renewal Opportunity - Must be Won and Closed, etc.
   
   if (trigger.isUpdate){
   for (Opportunity opp : Trigger.new){
       System.debug('Opportunity: ' + opp.Name + ', Stage: ' + opp.StageName);
              if(opp.StageName == 'Customer - Closed Won'){
                     if(opp.Type == 'Renewal' || opp.Type =='Renewal and Expansion' || opp.Type == 'New - Enterprise' || opp.Type == 'New Business Expansion'){
                      System.debug(LoggingLevel.Error, 'Opp ID: ' + opp.Id);
                    
                      //Renewal Date Calculations - Renewal Start and End Dates
                      Date contractStartDate = opp.Contract_Start_Date__c;
                      integer duration = (integer)opp.Contract_Duration_Months__c;
                      
                      Date renewalStartDate = contractStartDate.addMonths(duration);
                         system.debug(renewalStartDate);
                           Account acct = accts.get(opp.AccountId);
                           String acctName = acct.Name;
                      
                        String stage = 'SAL Demo Scheduled';
                        decimal amount;
                         
                         if(opp.License__c != null && opp.Contract_Increase__c!=null ){
                         amount =  ((opp.Contract_Increase__c/100)+1) * opp.License__c; 
                        }
                         else{amount = opp.License__c;}
                      
                       
                         system.debug(amount);
               
                      String title = String.valueOf(renewalStartDate.year()) + '_Renewal_' + acctName + '_$' + String.valueOf(amount.format());
                  
                      OpportunityContactRole[] oppconroles = [SELECT IsPrimary, ContactId FROM OpportunityContactRole WHERE OpportunityId = :opp.Id];
                    
                    boolean exists = false;
                    for (Opportunity o : opps) {
                       if (o.Name == title) {
                            exists = true;
                            System.debug(LoggingLevel.Error, o.Name + ' already EXISTS');
                       }
                      }
                    
                         
                         if(!exists){  
                      Opportunity ren_opp = opp.clone(false, true, false, false);
                       ren_opp.License__c = amount;
                       ren_opp.Amount = amount;
                       ren_opp.Previous__c = opp.License__c;
                        system.debug(ren_opp.License__c);
                        ren_opp.StageName = stage;
                        ren_opp.Contract_Start_Date__c = renewalStartDate;
                        ren_opp.Contract_Duration_Months__c = duration;
                        ren_opp.CloseDate = renewalStartDate;
                        ren_opp.Type = 'Renewal';
                        ren_opp.Probability = 10;
                        if(ren_opp.Contract_Increase__c>0){
                                ren_opp.Type='Renewal and Expansion';}
                            
                       
                       ren_opp.Name = title;
                  
                        //System Information deletions
                        ren_opp.CampaignId = null;
                        ren_opp.Date_moved_to_Closed_Lost__c = null;
                        ren_opp.Date_moved_to_Closed_Won__c = null;
                        ren_opp.Date_moved_to_Contract_Sent__c = null;
                        ren_opp.Date_moved_to_Demo_Complete__c = null;
                        ren_opp.Date_moved_to_Demo_Scheduled__c = null;
                        ren_opp.Date_moved_to_Verbal_Commit__c = null;
                        ren_opp.Date_moved_to_Proposal_Sent__c = null;
                        ren_opp.Amount_at_Closed_Lost__c = null;
                        ren_opp.Amount_at_Closed_Won__c = null;
                        ren_opp.Amount_at_Contract_Sent__c = null;
                        ren_opp.Amount_at_Demo_Complete__c = null;
                        ren_opp.Amount_at_Demo_Scheduled__c = null;
                        ren_opp.Amount_at_Proposal_Sent__c = null;
                        ren_opp.Amount_at_Verbal_Commit__c = null;

                        //SOW Deletions
                        ren_opp.Unique_Pricing_Scenario__c = null;
                        ren_opp.Department__c = null;
                        ren_opp.Signature_Events__c = null;
                        ren_opp.Number_of_Seats__c = null;
                        ren_opp.Special_Admin_Structure__c = null;
                        ren_opp.Design_Resources__c = null;
                        ren_opp.Needs_Designer_Pro__c = false;
                        ren_opp.Key_Functionality_Landmines__c = null;
                        ren_opp.Custom_Dev_Work__c=null;
                        ren_opp.Splash_User_Experience__c=null;
                        ren_opp.Kickoff_Email_Recipients__c=null;
                        ren_opp.Imminent_Deadline__c=null;
                        ren_opp.Client_Fears_or_Concerns__c=null;
                        ren_opp.Opportunities_for_Growth__c = null;
                        ren_opp.Opportunities_for_Growth_Yes__c = null;
                        ren_opp.Additional_Comments__c = null;
                        ren_opp.Require_Starter_Themes__c = null;
                       // ren_opp.SOW_End_Date__c = renewalStartDate;
                        
                        ren_opp.Primary_Purpose_of_Events__c = null;

                        //Docusign deletions     
                        ren_opp.DocuSign_Status__c = null;
                    
                        //Discovery Questions deletions   
                        ren_opp.Annual_of_Events__c = null;
                        ren_opp.CRM__c=null;
                        ren_opp.CRM_Other__c=null;
                        ren_opp.CRM_Other__c = null;
                        ren_opp.Budget__c = null;
                        ren_opp.Purpose_of_Events__c = null;
                        ren_opp.Purpose_of_Events_Other__c=null;
                        ren_opp.What_are_they_currently_using__c = null;
                        ren_opp.Marketing_Automation__c = null;
                        ren_opp.Marketing_Automation_Other__c = null;
                        ren_opp.Role_of_Primary_Contact__c = null;
                        ren_opp.Role_of_Primary_Contact_other__c = null;
                        ren_opp.Current_process_for_event_program__c = null;
                        ren_opp.Currently_using_other__c = null;
                        ren_opp.Value_Driver_details__c = null;
                        ren_opp.Primary_Purpose_of_Events_Other__c = null;
                        ren_opp.Need_SPS__c = null;
                  
                        //Other Deletions   
                        ren_opp.ForecastCategoryName = 'Pipeline';
                        ren_opp.Agreed_to_Case_Study__c = false; 
                         
                             insert ren_opp;
                             List<OpportunityContactRole> rolesToInsert = new List<OpportunityContactRole>();
                             for (OpportunityContactRole opprole : oppconroles) {
                            System.debug(LoggingLevel.ERROR, 'ContactRole: ' + opprole.ContactId);
              OpportunityContactRole ocp = opprole.clone(false, true, true, true);
                            ocp.OpportunityId = ren_opp.Id;
                            rolesToInsert.add(ocp);
                        }
                        
                        if (rolesToInsert.size() > 0) {
                            insert rolesToInsert;
                        }
          
                           update ren_opp;
                        
             }                      else{}       
           }            else{
                          System.debug('Case is not of the correct type');
       }    
    }         else{ 
                System.debug('Case '+ opp.Name + ' is not Closed and Won');
   }
  }
 }
}