Trigger Challenge #4: Write a trigger when an opportunity name is modified , create a task to the owner of the record.

0
1694

Hello Salesforce Cody’s, Welcome back after a long time. Let’s do a quick Beginner/Intermediate level trigger.

Trigger Challenge #4: Write a trigger when an opportunity name is modified , create a task to the owner of the record.
trigger nameModifyOppTrigger on Opportunity (after update) {
	List<Task> tasks = new List<Task>();
    for(Opportunity opp : Trigger.New){
        if(opp.Name != Trigger.oldmap.get(opp.Id).Name){
         	tasks.add(new Task(OwnerId = opp.OwnerId,Subject = 'Follow Up Test Task',WhatId = opp.Id));   
        } 
    }
    if(tasks.size() > 0){
        insert tasks;
    }  
}

Let me know in the comments if any doubts?