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
Avin KramerAvin Kramer 

Trigger to update a field when a task is created on contact

I'm new to triggers. I want to update a custom field (checkbox on Contacts) when a task or event is created/updated on Contacts by all profiles but admins. 

Can someone please give me a sample code?
Gabriel ArribasGabriel Arribas
Hi Avin,

I think its easier do this process with a workflow in Process Builder because is a simple operation.

Create the process starting when a Task is created or updated, add a criteria if you wish and on action select an the checkbox 'Select an object related to Task', select fhe Contact field and value desired.

If this resolve your issue, mark as best answer.
Rohit Sharma 66Rohit Sharma 66
Try create a workflow. If its just for learning let me know if you need to write a trigger for this.
Avin KramerAvin Kramer
Gabriel - I did follow your steps but I don't see any contact related fields as an option in the list of avaliable drop downs.

Rohit Sharma - It is not possible by workflow as task is a cross reference object, i would not be able to do any updates on contacts? I think trigger might help in this regard. 
Gabriel ArribasGabriel Arribas
Hello Avin, 

I add some screenshot that I hope help you.

1. In the drop-down setting the action, mark Update Records. 
User-added image

2. In the record type, you can choose 'Select a record related to the Task'. 
User-added image
Avin KramerAvin Kramer
Gabriel thank you for the screenshots but i still don't see contact related fields in the search dialog box. Can you see them?