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
Tapas TuloTapas Tulo 

opportunity stage is set to Won or Lost, new opportunity should get created automatically with existing opportunity information

When the opportunity stage is set to Won or Lost, new opportunity should get created automatically with existing opportunity information For Next year
Ex-EventDate=03/02/2017 than it should be 03/02/2018 for upcoming next year opportunity
 
 here My Code:-
===========================================================*/
public class opportunityTriggerHandler{

    // Method to create future Opportunity while closing oprtunity
    
    public static void opportunityClone(list<Opportunity> opportunityList){
        list<Opportunity> oppLst=[SELECT id,Name,LeadSource,Region__c,StageName,Event_Frequency__c,Event_Date__c, Account.Name FROM Opportunity WHERE ID IN: trigger.new];
        Map<Id,Opportunity> opportunityMapOld = (Map<Id,Opportunity>)Trigger.OldMap; 
        list<Opportunity> OppList= new list<Opportunity>();
        
        for(Opportunity opp: oppLst){
            if(opp.Event_Frequency__c!='0'){
            // check opportunity Stage changed
            if(opp.StageName!=opportunityMapOld.get(Opp.Id).StageName && (Opp.StageName=='Event Won' || Opp.StageName=='Event Lost')){
                Opportunity OppReference= new Opportunity();
                OppReference.Name=opportunityMapOld.get(Opp.Id).Name;
                system.debug('OppAccname'+opp.Account.Name);
                OppReference.Account = opportunityMapOld.get(Opp.Id).Account;
                OppReference.LeadSource=opportunityMapOld.get(Opp.Id).LeadSource;
                OppReference.Status__c ='Open';
                OppReference.Region__c=opportunityMapOld.get(Opp.Id).Region__c;
                OppReference.StageName = '---None---';
                OppReference.Probability = 0;
                OppReference.CloseDate = system.today().addMonths(1);
                if(opp.Event_Date__c!=null){
                    OppReference.Event_Date__c = opportunityMapOld.get(Opp.Id).Event_Date__c;
                }   
                else{
                    OppReference.Event_Date__c =system.today().addMonths(12);
                    //OppReference.closeDate=system.today().addMonths(12);
                }
                OppList.add(OppReference);
                }
            }
        }
        if(!OppList.isEmpty())
        Insert OppList;
    }
    
    public static void ownerChange(list<Opportunity> OppList){
        
        set<string> strRoleName= new set<string>{'Bangalore', 'Mumbai', 'Delhi'};
        list<User> userRecords= [SELECT id, UserRole.Name FROM User WHERE UserRole.Name IN: strRoleName];
        map<string, Id> maoRoleNameandUserId= new map<string, Id>();
        for(user u: userRecords){
            maoRoleNameandUserId.put(u.UserRole.Name, u.id);
        }
        for(opportunity op: OppList){
        if(maoRoleNameandUserId.containsKey(op.Region__c))
            op.OwnerId=maoRoleNameandUserId.get(op.Region__c);
        }
    }
}

Executed Successfully But NOt getting the Result.
It would be great if i get the answer

Thanks&Regards,
Tapas
 
SalesFORCE_enFORCErSalesFORCE_enFORCEr
Did you try creating a process builder? You can easily achieve this functionality using a builder.