function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Maheswara Reddy 25Maheswara Reddy 25 

auto-create a new Opportunity (Similar to an old record) whenever an Opportunity is successfully closed and set the Close date for the new Opportunity to 120 days from the old opportunity’s close date using trigger.

Best Answer chosen by Maheswara Reddy 25
CharuDuttCharuDutt
Hii Maheswara
Try Below Trigger
trigger opptyTrigger on Opportunity (after update) {
    list<Opportunity> lstopp = new list<Opportunity>();
    for(opportunity opp : trigger.new){
       if(opp.StageName == 'Closed Won' && Opp.StageName != trigger.oldMap.get(Opp.Id).StageName && Opp.AccountId != Null){
          Opportunity opp1 = new Opportunity();
           opp1.Name = opp.Name + 'new';
           opp1.AccountId = opp.AccountId;
           opp1.CloseDate = opp.CloseDate.addDays(120);
           opp1.StageName = 'Prospecting';
           lstopp.add(opp1);
       }
    }
    if(lstOpp.size()>0){
        insert lstOpp;
    }
}
Please Mark It As Best Answer If It Helps
Thank You!

All Answers

CharuDuttCharuDutt
Hii Maheswara
Try Below Trigger
trigger opptyTrigger on Opportunity (after update) {
    list<Opportunity> lstopp = new list<Opportunity>();
    for(opportunity opp : trigger.new){
       if(opp.StageName == 'Closed Won' && Opp.StageName != trigger.oldMap.get(Opp.Id).StageName && Opp.AccountId != Null){
          Opportunity opp1 = new Opportunity();
           opp1.Name = opp.Name + 'new';
           opp1.AccountId = opp.AccountId;
           opp1.CloseDate = opp.CloseDate.addDays(120);
           opp1.StageName = 'Prospecting';
           lstopp.add(opp1);
       }
    }
    if(lstOpp.size()>0){
        insert lstOpp;
    }
}
Please Mark It As Best Answer If It Helps
Thank You!
This was selected as the best answer
Maheswara Reddy 25Maheswara Reddy 25
Thank you Mr.CharuDutt
Could you please provide Test class for that Triiger.It will be helpfull.