Create an Apex trigger for Opportunity that adds a task to any opportunity set to Closed Won

trigger ClosedOpportunityTrigger on Opportunity (before insert, before update) {
    List<Task> listTask = new  List<Task>();
    for(Opportunity opp : Trigger.New){
        if(opp.StageName=='Closed Won'){
            Task t= new Task();
            t.subject = 'Follow Up Test Task';
            t.WhatId = opp.Id;
            listTask.add(t);
        }
    }
    insert listTask;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章