You need to sign in to do that
Don't have an account?
randombard
For each loop to close tasks on opportunity
Hi All,
Little stuck on this one in the following code how do I first add another variable to the SOQL to only include Tasks with the Subject Line 'Opportunity Past Close Date' and then go through the list as a for each loop closing them.
The code I have right now will just close one and I can tell that's because of the line
TasksToClose[0].Status = 'Completed';}
But I can't work out how to make that an integer
trigger Close_Tasks on Opportunity (after insert, after update) { for(Opportunity o: trigger.new) { If((o.stagename=='Closed Won')) {List<Task> TasksToClose = new List<Task>(); {TasksToClose = [select Id,WhatID,Status from Task where WhatID=:o.Id]; TasksToClose[0].Status = 'Completed';} update TasksToClose; } else { } } }
Thanks
R
In Case anyone else has this issue the following seems to work for me
All Answers
Try this.
Hello and thanks for the help.
I get the following error
Error: Compile Error: line breaks not allowed in string literals at line 15 column -1
If I change the code to as follows
I get:
Error: Compile Error: Duplicate variable: TasksToClose (attempt to re-create the variable with type: updatde) at line 22 column 13
This appears to be in reference to:
In Case anyone else has this issue the following seems to work for me