You need to sign in to do that
Don't have an account?
Pritesh Khole 1
Apex trigger for Renewal opportunity
Hi Team,
I am trying to create a renewal opportunity along with the product, based on some condition. I have written a trigger, however the opportunity is getting renewed but the products are not. Is there anything that I am missing. Require some help. Below is my code
trigger RenewalOpportunityProcess on Opportunity (after insert,after update) {
Map<Opportunity,List<OpportunityLineItem>> OpportunityLineItemsMapping = new Map<Opportunity,List<OpportunityLineItem>>();
List<Opportunity> listOpp = new List <Opportunity>(); //List of Opportunity to store all the renewal Opportunities
//Create Renewal Opportunity when stage is 'Closed Won ' and 'Create Future Renewal Opportunity' is Yes.
for (Opportunity opp:Trigger.new){
opp = [Select Name,StageName,AccountId, (SELECT Quantity, TotalPrice, PricebookEntry.Name, PricebookEntry.Product2.Family FROM OpportunityLineItems) from Opportunity where id=:opp.Id LIMIT 1 ];
if(opp.StageName == 'Closed Won' && opp.AccountId != null && opp.Create_Future_Renewal_Opportunity__c == 'Yes' && opp.HasOpportunityLineItem == true)
{
Opportunity oppNew = opp.clone(false,true); //This clone method Creates a copy of the sObject record.
oppNew.StageName = 'Qualification';
oppNew.Name = opp.Name + ' - ' + 'RENEWAL';
listOpp.add(oppNew);
OpportunityLineItemsMapping.put(oppNew,opp.OpportunityLineItems.deepClone(false,false,false));
}
insert listOpp;
}
}
I am trying to create a renewal opportunity along with the product, based on some condition. I have written a trigger, however the opportunity is getting renewed but the products are not. Is there anything that I am missing. Require some help. Below is my code
trigger RenewalOpportunityProcess on Opportunity (after insert,after update) {
Map<Opportunity,List<OpportunityLineItem>> OpportunityLineItemsMapping = new Map<Opportunity,List<OpportunityLineItem>>();
List<Opportunity> listOpp = new List <Opportunity>(); //List of Opportunity to store all the renewal Opportunities
//Create Renewal Opportunity when stage is 'Closed Won ' and 'Create Future Renewal Opportunity' is Yes.
for (Opportunity opp:Trigger.new){
opp = [Select Name,StageName,AccountId, (SELECT Quantity, TotalPrice, PricebookEntry.Name, PricebookEntry.Product2.Family FROM OpportunityLineItems) from Opportunity where id=:opp.Id LIMIT 1 ];
if(opp.StageName == 'Closed Won' && opp.AccountId != null && opp.Create_Future_Renewal_Opportunity__c == 'Yes' && opp.HasOpportunityLineItem == true)
{
Opportunity oppNew = opp.clone(false,true); //This clone method Creates a copy of the sObject record.
oppNew.StageName = 'Qualification';
oppNew.Name = opp.Name + ' - ' + 'RENEWAL';
listOpp.add(oppNew);
OpportunityLineItemsMapping.put(oppNew,opp.OpportunityLineItems.deepClone(false,false,false));
}
insert listOpp;
}
}
All Answers