Question: We have a requirement:  

We have fields in the opportunity called as **`MIDescription`** Whenever we entered in the description field it should create a new brand task in the Open Activities related list. For that we have created a one trigger in opportunity mentioned below. Trigger is working but we haven't updated anything in the Description field but it has automatically creating a new task.  
Can you please help us the trigger where i made the mistakes.

```
Trigger Description on Opportunity(before insert, before update) {
    Set < Id > opIds = new Set < Id > ();
    List < Task > taskList = new List < Task > ();
    List < Opportunity > Opps = Trigger.new;
    //List<Opportunity> taskOps = [Select Id,Help__c,Description__c from Opportunity where Id in :opIds];
    for (Opportunity Opp: Opps) {
        Task t = new Task();
        t.WhatId = opp.Id;
        t.Subject = 'Task';
        taskList.add(t);
    }
    insert taskList;
}

```

Thanks in advance.

Answer: 
It is creating every time you are updating opportunity. You need to put some check in your code to verify if the MIDescription is updated. 

You can use **trigger.oldMap** to verify the changes in the value of MIDescription and then create a task. Use following code and let me know if it works.

```
Trigger Description on Opportunity(before update) {
    Set < Id > opIds = new Set < Id > ();
    List < Task > taskList = new List < Task > ();
    List < Opportunity > Opps = Trigger.new;

    for (Opportunity Opp: Opps) {
    if(opp.Description__c != Trigger.oldMap.get(opp.id).MI_Description__c){
        Task t = new Task();
        t.WhatId = opp.Id;
        t.Subject = 'Task';
        taskList.add(t);
    }
    }
    insert taskList;
}

```
```
Trigger.isInsert trigger context is used to check whether Trigger was fired due to Insert operation, in that case we want to create Task. 
Trigger.isUpdate trigger context is used during Update operation, get Old map from Trigger context check if Description(or any other field) got changed, then create Task

trigger Opportunity_Create_Task on Opportunity (before insert, before Update) {
Set < Id > opIds = new Set < Id > ();
List < Task > taskList = new List < Task > ();
List < Opportunity > Opps = Trigger.new;
List<Opportunity> taskOps = [Select Id,Description from Opportunity where Id in :opIds];
//Insert Opertaion
if(Trigger.isInsert){
   for (Opportunity Opp: Opps) {
        Task t = new Task();
        t.WhatId = opp.Id;
        t.Subject = 'QMI Task';
        taskList.add(t);
    }
}
//Update Operation
if(Trigger.isUpdate){
    Map<Id,Opportunity> oldOppMap = Trigger.oldmap;
     for (Opportunity Opp: Opps) {
         //Check If description got changed
         if(Opp.description != oldOppMap.get(opp.Id).description){
            Task t = new Task();
            t.WhatId = opp.Id;
            t.Subject = 'QMI Task';
            taskList.add(t);
         }

    }
}

insert taskList;

```

}