Hola buen día. He tratado de realizar el reto pero no logro aprobarlo, ya he modificado el trigger de varias formas y no logro aprobar, ya lo he testeado por "Execute Anonymous Windows" y allí funciona bien, pero al validar el reto me dice que "Se creó una oportunidad pero no una tarea". Esta es la versión inicial: trigger ClosedOpportunityTrigger on Opportunity (after insert, after update) { List<Task> tasks = new List<Task>(); for (Opportunity opp : Trigger.New) { System.debug('##### ' + opp.StageName); if(opp.StageName == 'Closed Won') { tasks.add(new Task(Subject='Follow Up Test Task', WhatId=opp.Id)); } } System.debug('tasks ' + tasks.size()); if (tasks.size() > 0) { insert tasks; System.debug('tasks Inserted'); } } Ya la he cambiado hasta esto y no consigo que funcione: trigger ClosedOpportunityTrigger on Opportunity (after insert, after update) { List<Task> tasks = new List<Task>(); List<Opportunity> toProcess = null; switch on Trigger.operationType { when AFTER_INSERT { toProcess = Trigger.New; } when AFTER_UPDATE { toProcess = [SELECT Id, StageName FROM Opportunity WHERE Id IN :Trigger.New /*AND StageName = 'Closed Won'*/]; } } for (Opportunity opp : toProcess) { System.debug('##### ' + opp.StageName); if(opp.StageName == 'Closed Won') { Task ta = new Task(Subject='Follow Up Test Task', WhatId=opp.Id); //tasks.add(new Task(Subject='Follow Up Test Task', WhatId=opp.Id)); tasks.add(ta); } } System.debug('tasks ' + tasks.size()); if (tasks.size() > 0) { insert tasks; System.debug('tasks Inserted'); } } Agradezco cualquier ayuda. Saludos.
Hi, @Arnab Mukherjee
,
Thank you very much for your attention. It worked now, I just had to log out and log back in, and it worked without any problems. It is likely that something was wrong that was only corrected with the data from a new session.
Thank you!!!
We are glad that your issue was resolved. Could you please mark your answer as "Best Answer" to close this thread. So that it might help the fellow Trailblazer's who are facing the similar issue.
Thank You!!