Skip to main content
2 of 2
added 130 characters in body
Sebastian Kessel
  • 13.2k
  • 12
  • 38
  • 61

Here is my code : if you want to go with apex class

==================Apex Class =======================

public class OpportunityApexClass {
    
    public static void opportunityTrigger(list<Opportunity> varOpportunity)
    {
        list<Task> varTask = new list<Task>();
     for(Opportunity varopp : varOpportunity)
        {
         if(varopp.StageName == 'Closed Won')
            { 
                Task varTa = New Task();
                varTa.Subject ='Follow Up Test Task';
                varTa.Status ='Not Started';
                varTa.WhatId = varopp.Id;
                 varTask.add(varTa);
            } 
        }
         insert varTask; 
    }
}

===================Trigger==========================

trigger ClosedOpportunityTrigger on Opportunity (before insert,before update) {
    
    if(Trigger.isbefore == True && Trigger.isinsert == True)
    {
        OpportunityApexClass.opportunityTrigger(Trigger.new);   
    }
    if(Trigger.isbefore == True && Trigger.isupdate == True)
    {
        OpportunityApexClass.opportunityTrigger(Trigger.new);
    }

}