+ Start a Discussion
jmaskell123jmaskell123 

Renewal Opportunity - Code

Hi 

 

I am using the following Trigger to create a renewal opportunity for a years time.

 

 

trigger RenewalOpportunity on Opportunity (after update) { for (Integer i = 0; i < Trigger.new.size(); i++) { System.debug('checking opportunity ' + i); System.debug('old.isWon: ' + Trigger.old[i].isWon); System.debug('new.isWon: ' + Trigger.new[i].isWon); if (Trigger.new[i].isWon == true && Trigger.old[i].isWon == false) { Date endDate = Trigger.new[i].CloseDate.addDays(365); System.debug('updating opportunity ' + i); Opportunity renewalOpp = Trigger.new[i].clone(false); renewalOpp.Name = 'Renewal - '+ Trigger.new[i].Name; renewalOpp.closedate = endDate; renewalOpp.stagename = 'D - Relationship Management'; insert renewalOpp; if (Trigger.new[i].Name.startsWith('Renewal - ')) { renewalOpp.Name = Trigger.new[i].Name; update renewalOpp; } System.debug('renewal opportunity inserted' + i); System.debug('renewalOpp.id: ' + renewalOpp.ID); System.debug('TriggerNew[i].id: ' + Trigger.new[i].ID); if (Trigger.new[i].isWon == true && Trigger.old[i].isWon == false) { System.debug('Associating generated opportunity as child of closed->won opportunity'); Opportunity newOpp = [select ID from Opportunity where id = :Trigger.new[i].ID]; newOpp.Renewal_Opportunity__c = renewalOpp.ID; update newOpp; } } } }

Is there a way of edditing the triger so that it is only takes place if a feild on the opportuntiy called " Create Renewal " is ticked.

 

Hope someone can help.

 

Regards

 

Jake 

 

 

Message Edited by jmaskell123 on 08-10-2009 02:37 AM
Message Edited by jmaskell123 on 08-10-2009 02:39 AM