You need to sign in to do that
Don't have an account?
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;
}
}
}
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