• bbeth soutullo
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hello Community! Hope im finding you all doing alright.
Im studying apex and im kind of stuck in a Trail about bulk triggers.
I've found the answer to the challenge in another post but i want to know what is wrong with my approach since i dont seem to understand, would someone explain what is wrong with my code?
i've wrote the following:


Create a bulkified Apex trigger that adds a follow up task to an opportunity if its stage is Closed Won. Fire the trigger after inserting or updating an opportunity.
Name: ClosedOpportunityTrigger
Object: Opportunity
Events: after insert and after update
Condition: Stage is Closed Won
Operation: Create a task:
Subject: Follow Up Test Task
WhatId = the opportunity ID (associates the task with the opportunity)

 
trigger ClosedOpportunityTrigger on Opportunity (after insert, after update) {
    List<Opportunity> oppIDs = [SELECT Id FROM Opportunity WHERE id IN :Trigger.New];
    for (Opportunity opp: oppIDs){
        if (opp.StageName == 'Closed Won'){
            Task newTask = new Task();
            newTask.Subject = 'Follow Up Test Task';
			newTask.WhatId = opp.Id;
            insert newTask;
        }
    }

Thank you so much in advance!
Hello Community! Hope im finding you all doing alright.
Im studying apex and im kind of stuck in a Trail about bulk triggers.
I've found the answer to the challenge in another post but i want to know what is wrong with my approach since i dont seem to understand, would someone explain what is wrong with my code?
i've wrote the following:


Create a bulkified Apex trigger that adds a follow up task to an opportunity if its stage is Closed Won. Fire the trigger after inserting or updating an opportunity.
Name: ClosedOpportunityTrigger
Object: Opportunity
Events: after insert and after update
Condition: Stage is Closed Won
Operation: Create a task:
Subject: Follow Up Test Task
WhatId = the opportunity ID (associates the task with the opportunity)

 
trigger ClosedOpportunityTrigger on Opportunity (after insert, after update) {
    List<Opportunity> oppIDs = [SELECT Id FROM Opportunity WHERE id IN :Trigger.New];
    for (Opportunity opp: oppIDs){
        if (opp.StageName == 'Closed Won'){
            Task newTask = new Task();
            newTask.Subject = 'Follow Up Test Task';
			newTask.WhatId = opp.Id;
            insert newTask;
        }
    }

Thank you so much in advance!