Thanks for your help!trigger ClosedOpportunityTrigger on Opportunity (after insert, after update) {
List<Task> taskList = new List<Task>();
for (Opportunity opp : [SELECT Id, StageName FROM Opportunity WHERE StageName = 'Closed Won' AND Id IN :Trigger.new]){
taskList.add(new Task(Subject = 'Follow Up Test Task',
WhatId = opp.Id));
}
if(taskList.size()>0){
insert taskList;
}
}
2 respuestas
Hi Alexis,It looks like you have a field (Discount_Percent__c) on the Task object that is required, so you need to add that when creating a new Task record. So change line 7 of your code to this...taskList.add(new Task(Subject = 'Follow Up Test Task', Discount_Percent__c = 0, WhatId = opp.Id));If you have an actual Discount Percentage you can use that, but in my example I'm just setting it to 0.I hope this helps.Jason