You need to sign in to do that
Don't have an account?
Abby Stocker
Trigger - Prevent user from closing a case if tasks are still open.
Hello! I have looked online for this and found 2 answers but neither truly make sense to me as to what the triggers are actually doing. I was wondering if someone could help me accomplish and understand an apex trigger. The requirement is that a case cannot be closed if it has an associated task that is still open. Thank you!!!!
IF(current record field == X)
Then I would SOQL the TASK object where the WHATID = current record AND Status <> Completed. I would get a count of the task that match that criteria. If it is > 0, then display a warning to the user letting them know they have to close all task before they can select that option.
If my answer helped you, please mark as best
Brandon Nelson
Salesforce Admin/Developer
trigger OpenTasksOnCase on Case (before update) {
For(Case c : Trigger.New)
then SQL c for CaseNumber, Status when status <> Completed
and SQL Task for WhatId, Status when status <> Closed
If record count of open tasks associated with case is >0, add error message displaying that they may not close the case with open tasks?
Would you are anyone be able to assist on formatting this trigger? What the actual code should look like?
I've gone through your requirement and you can refer the below code or you can also use it for your requirement:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com