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
priya sripriya sri 

Trigger for opportunity is renewal then its become clone

when ever opportunity is renewal then its become clone...
for this :::

trigger RenewalOpportunityClone on Opportunity (after update, after insert) {
    List<Id> opps = new List<Id>();
    
    for( Opportunity opp : Trigger.new ) {
        if ( opp.RecordTypeId != '01290000000Hqw2' ) 
{
            continue;
        }
        
        if( !opp.Renew_Now__c)  {
            continue;
        }

        opps.add( opp.Id );
    }
    
    
    Map<Id,Opportunity> oppsMap = new Map<Id,Opportunity>( [SELECT Id,OwnerId,Account.OwnerId, Original_Opportunity_ID__c,AccountId, Branch__c,Line_of_Business__c,Name,Contact__c,Renew_Now__c,Monthly_Spend__c, RecordTypeId from Opportunity where Id IN :opps] );
    
    List<Opportunity> renewalOpps = new List<Opportunity>();
    
    for( Opportunity opp : oppsMap.values() ) {
        Opportunity renewalOpp = new Opportunity();
        
        Date renewalDate = Date.today();
        Date closeDate = Date.today();
        
        
        String renewalDateString = '' + renewalDate;
        renewalDateString = renewalDateString.substring(0, renewalDateString.indexOf(' '));
        
        renewalOpp.CloseDate = closeDate + 365;
        renewalOpp.OwnerId = opp.Account.OwnerId;
        renewalOpp.AccountId = opp.AccountId;
        renewalOpp.Contact__c= opp.Contact__c;
        renewalOpp.NextStep= 'Review Account Status, send renewal notice and quote.';
        
        renewalOpp.Monthly_Spend__c = opp.Monthly_Spend__c;
        renewalOpp.StageName = 'First Meeting';
        renewalOpp.Branch__c = opp.Branch__c;
        renewalOpp.Line_of_Business__c= opp.Line_of_Business__c;
        renewalOpp.Name = opp.Name;
        renewalOpp.Original_Opportunity_ID__c=opp.Original_Opportunity_ID__c;
        renewalOpp.Is_Cloned__c = true ;
        renewalOpp.Cloned_from_Opportunity_ID__c='https://cs5.salesforce.com/'+opp.Id;
        renewalOpps.add(renewalOpp);
        opp.Renew_Now__c = false ;
        opp.Is_Master__c = false ;
        
        update opp;
    }
    
    insert renewalOpps;
    
    
    
    
}

















 
SonamSonam (Salesforce Developers) 
Are you facing any errors with this code or is it not giving the desired result? please specify the error so we can suggest better.
priya sripriya sri
hi sonam
     its not updating the close date??? 
    it has to update close date before 90days??

thankyou sonam