You need to sign in to do that
Don't have an account?
Clone opportunity with products through apex trigger
Hi ,
I have written the code to clone opportunity from apex trigger but i am concerned why the products are not getting clonned
Also if productname (i.e., ends with "-Y" ) then clonned date of opp = system.today
Can anyone please advise or help me with suitable solution .
Thanks & Regards
Paarth Jolly
I have written the code to clone opportunity from apex trigger but i am concerned why the products are not getting clonned
Also if productname (i.e., ends with "-Y" ) then clonned date of opp = system.today
Trigger OpportunityTrigger on Opportunity(before insert, before update){ Set<ID> Idset = new Set<ID>(); List<Opportunity> oppLstToUpdate=new List<Opportunity>(); if(Trigger.isInsert){ List<Opportunity> clonedRecords = new List<Opportunity>(); Opportunity newOpp= new Opportunity(); for(Opportunity opp : Trigger.new){ if((opp.Name == 'ServiceDesk Online - Monthly Usage' || opp.Name == 'ServiceDesk Online Purchase') && opp.StageName == 'Closed Won'){ newOpp = opp.clone(false, false, false, false); newOpp.Name = 'ttttt'; newOpp.Closedate = opp.Date_After_1_Month__c; newOpp.StageName = 'zzzzz'; clonedRecords.add(newOpp); } } if(clonedRecords.size() > 0){ insert clonedRecords; } } if(Trigger.isUpdate){ List<Opportunity> clonedRecords = new List<Opportunity>(); Opportunity newOpp= new Opportunity(); for(Opportunity opp : Trigger.new){ if((opp.Name == 'ServiceDesk Online - Monthly Usage' || opp.Name == 'ServiceDesk Online Purchase' )&& opp.StageName == 'Closed Won'&& opp.StageName != trigger.oldMap.get(opp.Id).StageName){ newOpp = opp.clone(false, false, false, false); newOpp.Name = 'ttttt'; newOpp.Closedate = opp.Date_After_1_Month__c; newOpp.StageName = 'zzz'; clonedRecords.add(newOpp); } } if(clonedRecords.size() > 0){ insert clonedRecords; } } }
Can anyone please advise or help me with suitable solution .
Thanks & Regards
Paarth Jolly