Created
September 29, 2014 07:02
-
-
Save arufian/052562a1ef3b18dbf316 to your computer and use it in GitHub Desktop.
A Solution for SFDC99 Opportunity Renewal challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger CreateRenewal on Opportunity (after insert, after update) { | |
List<Opportunity> renewals = new List<Opportunity>(); | |
List<Opportunity> closedOpp = Trigger.new; | |
RecordType renewalRecordType = [SELECT Id FROM RecordType WHERE Name LIKE '%Renewal%']; | |
for(Opportunity opp: closedOpp){ | |
if(opp.IsClosed){ | |
Opportunity newOpp = new Opportunity(); | |
newOpp.AccountId = opp.AccountId; | |
newOpp.Name = opp.Name+'Renewal'; | |
newOpp.StageName = 'Open'; | |
newOpp.CloseDate = opp.CloseDate + 365; | |
newOpp.RecordTypeId = openRecordType.Id; | |
newOpp.OwnerId = opp.OwnerId; | |
renewals.add(newOpp); | |
} | |
} | |
insert renewals; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment