You need to sign in to do that
Don't have an account?
Punima Sharma
Apex Trigger
Hi,
I am not able to complete Trailhead:Bulk Apex Triggers challenge ,I am facing issue ' Challenge not yet complete... here's what's wrong:
Executing against the trigger does not work as expected'. Debug logs are also not descriptive like error message.
Code :
trigger ClosedOpportunityTrigger on Opportunity (after insert, after update) {
List<Task> tasks = new List<Task>();
for (Opportunity opp: Trigger.New) {
If (Trigger.isUpdate){
if(opp.StageName!=trigger.oldMap.get(opp.Id).stageName && opp.StageName == 'Closed Won'){
tasks.add(new Task(Subject = 'Follow Up Test Task',WhatId = opp.Id)) ;
}
}
If (Trigger.isInsert){
if(opp.StageName == 'Closed Won'){
tasks.add(new Task(Subject = 'Follow Up Test Task',WhatId = opp.Id)) ;
}
}
}
if (tasks.size()< 0){
insert tasks;
}
}
I have no workflow,flow or powerbuilder process related to opportunity.
P.S.
I have followed suggestion of other users (Chris Edwards and Sandeep Bhanot) which they have posted in a similar post but in my case this issue is not fixed.
I am not able to complete Trailhead:Bulk Apex Triggers challenge ,I am facing issue ' Challenge not yet complete... here's what's wrong:
Executing against the trigger does not work as expected'. Debug logs are also not descriptive like error message.
Code :
trigger ClosedOpportunityTrigger on Opportunity (after insert, after update) {
List<Task> tasks = new List<Task>();
for (Opportunity opp: Trigger.New) {
If (Trigger.isUpdate){
if(opp.StageName!=trigger.oldMap.get(opp.Id).stageName && opp.StageName == 'Closed Won'){
tasks.add(new Task(Subject = 'Follow Up Test Task',WhatId = opp.Id)) ;
}
}
If (Trigger.isInsert){
if(opp.StageName == 'Closed Won'){
tasks.add(new Task(Subject = 'Follow Up Test Task',WhatId = opp.Id)) ;
}
}
}
if (tasks.size()< 0){
insert tasks;
}
}
I have no workflow,flow or powerbuilder process related to opportunity.
P.S.
I have followed suggestion of other users (Chris Edwards and Sandeep Bhanot) which they have posted in a similar post but in my case this issue is not fixed.
if (tasks.size()< 0) {
This should be tasks.size()>0 meaning the size of the list is greater than 0.
All Answers
if (tasks.size()< 0) {
This should be tasks.size()>0 meaning the size of the list is greater than 0.
if (tasks.size()< 0){
insert tasks;
}
It should not be tasks.size() < 0 it should be tasks.size() > 0. A slight oversight i think.
Thanks,
Kaustav