function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Emelie ÖstEmelie Öst 

Completed task changes value in Case record

Hi,

Having issues to create a trigger that will change a boolean value in the case record once a related task changes status. When a task related to a case is set to status "Completed" and has the subject "Deactivation of ER" I want the Deactivated checkbox in the case to become checked. 

This is what I got, what am I missing? Tried changing it, but keep getting errors.. 

 


trigger Casedeactivated on Case (after insert, after update) {
set<id> caseId=new set<id>();
for(Task ts : trigger.new)
{
CaseId.add(ts.whatid);
Case cs=[Select status from Case where id in :caseId];
if(String.valueOf(ts.whatId).startsWith('005')==TRUE);
if(String.valueOf(ts.status).startsWith('Completed')==TRUE);
if(String.valueOf(ts.subject).startsWith('Deactivation')==TRUE)
{
cs.Deactivated__c='True';
update cs;
}
}
}

Shashikant SharmaShashikant Sharma
Hi,

You are missing the use case completelyhere, your trigger should be on Task object on after insert, after update events

Check only the tasks which
1. subject "Deactivation of ER"
2. Related to case records only here check for WhatId's first 3 characters have the '500'
3. Status changed to 'Çompleted'

If these satisfiled then updated the related case record's Deactivated__c .

Make sure you bulkify the trigger in order to make it work wit bulk data.
You could see this to learn more about trigger development  : http://forceschool.blogspot.in/search/label/Apex%20Triggers


 
Emelie ÖstEmelie Öst
I have no clue how to write this trigger, just tried changing some criterias from other triggers I found online.. Not a developer. 
Shashikant SharmaShashikant Sharma
Try to read the blog that I shared to develop it. If you face issues let me know I could help you resolving them.