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
TraciKimTraciKim 

Update a field on Case when a Task is Completed

Hello,

I'm looking for a way to update a checkbox field on the Case (Tax_Task_Completed__c) when a task opened against the case is completed. I've looked to do this declaratively, but I don't believe there's a way to do this... Any ideas on a simple trigger that might do the trick?  
Kiran RKiran R
You can certainly write a trigger. Using the WhatId in this case. Please, refer to the task/ events data model (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_erd_activities.htm) in their API docs.

Before going that far, I certain that, You can write a Process Builder on Task to look up its status and create an action to update the related records to selected the account and update it.

Search for the Process Builder in the Setup > Quick Find. Its' a wizard that'll let you pick your Object (Task) and then the corresponding acttions.

I believe this should work for you case. 
Kiran RKiran R
In case, If you had to write a trigger, it would be something like following mockup:
 
trigger task_After on Task (after insert) 
{
List<Account> AccountsToUpdate = new List<Account>();
for (Task t: Trigger.new)
{
if (t.Status=='Completed')
{
Account a = new Account(Id=t.WhatId);

a.Account_completion_Status = t.Status;
AccountsToUpdate.add(a);
}
}
   try {
        update AccountsToUpdate; 
    } catch (system.Dmlexception e) {
        system.debug (e);
    }
}