You need to sign in to do that
Don't have an account?
Abby Stocker
Trigger Error1
What would I do without the community!?
Please assist with the error for the trigger. Thank you!
CLASS------->
public class RelatedTasks {
public static boolean taskmethod(){
List<Task> tasks = [SELECT id, status from Task WHERE WhatId =:ApexPages.CurrentPage().getparameters().get('id') and status = 'Open'];
boolean isOpen = false;
for(Task t : tasks){
if(t.Status =='Open'){
isOpen = true;
}
}
return isOpen;
}
}
TRIGGER------------>
trigger getOpenTasks on Case (before update) {
for(Case c : Trigger.New){
If(RelatedTasks.taskmethod().isOpen==true){
c.adderror('You cannot close a case with an open task');
}
}
}
ERROR---------> Variable does not exist: isOpen
THANK YOU!!!
Please assist with the error for the trigger. Thank you!
CLASS------->
public class RelatedTasks {
public static boolean taskmethod(){
List<Task> tasks = [SELECT id, status from Task WHERE WhatId =:ApexPages.CurrentPage().getparameters().get('id') and status = 'Open'];
boolean isOpen = false;
for(Task t : tasks){
if(t.Status =='Open'){
isOpen = true;
}
}
return isOpen;
}
}
TRIGGER------------>
trigger getOpenTasks on Case (before update) {
for(Case c : Trigger.New){
If(RelatedTasks.taskmethod().isOpen==true){
c.adderror('You cannot close a case with an open task');
}
}
}
ERROR---------> Variable does not exist: isOpen
THANK YOU!!!
All Answers
Can you update the trigger as follows
Just wondering, what's the use case for this: From a trigger, you are calling an apex class and in that, you are using ApexPages.CurrentPage().getparameters().get('id').
Let's say when you'll update the case from data loader or apex, then how will you get the value for
Regards
-Ajeet JainSalesforcegig (https://salesforcegig.com)
public class currentCaseRecord {
Case currentRecord;
public currentCaseRecord (ApexPages.StandardController controller){
currentRecord = [Select Id FROM Case Where Id =:ApexPages.CurrentPage().getparameters().get('id')];
}
public case getcurrentRecord(){
return currentRecord;
}
}
Test this code please :
I believe, following trigger will be sufficient to achieve what you are looking for
Regards
-Ajeet Jain
First class is identifying the current case record ID:
public class currentCaseRecord {
Case currentRecord;
public currentCaseRecord (ApexPages.StandardController controller){
currentRecord = [Select Id,status FROM Case Where Id =:ApexPages.CurrentPage().getparameters().get('id') and status='closed'];
}
public case getcurrentRecord(){
return currentRecord;
}
}
Second class is returning all associated open tasks with that current case ID:
public class RelatedTasks {
public static boolean taskmethod(){
List<Task> tasks = [SELECT id, status from Task WHERE WhatId =:ApexPages.CurrentPage().getparameters().get('id') and status = 'Open'];
boolean isOpen = false;
for(Task t : tasks){
if(t.Status =='Open'){
isOpen = true;
}
}
return isOpen;
}
}
Finally, the trigger is supposed to be performing this : If a user closes a case but the case has associated open tasks, Throw an error "You cannot close a case with an open task".
trigger getOpenTasks on Case (before update) {
boolean isOpen = false;
for(Case c : Trigger.New){
isOpen = RelatedTasks.taskmethod();
If(isOpen){
c.adderror('You cannot close a case with an open task');
}
}
}
All of them are saved, No errors but when I try to even create a case I get yelled at with a bunch of errors. I do not want this trigger to fire unless the user attempts to close the case.
Any thoughts? (This is the very first trigger/class I have ever written so it has been quite a learning experience! lol) Thank you for any help!!!
Illegal assignment from List<Case> to Map<Id,Case>