Skip to content

Instantly share code, notes, and snippets.

@arufian
Created September 29, 2014 07:02
Show Gist options
  • Save arufian/052562a1ef3b18dbf316 to your computer and use it in GitHub Desktop.
Save arufian/052562a1ef3b18dbf316 to your computer and use it in GitHub Desktop.
A Solution for SFDC99 Opportunity Renewal challenge
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