You need to sign in to do that
Don't have an account?
MBarnard
Creating my first Apex Trigger - Cross Object update from Task to Account
Hey Guys,
Well, I have my lead weights on and am jumping off a 10' diving board into a 60' deep pool.
My first apex trigger.
I am looking to create a trigger, that when a task, that has a specific purpose is completed (purpose is a drop down field), it updates a notes field and date field within the Account object.
This is where i stand so far.
It is after insert.
I am going to try and use this as an open thread that I keep posting more into so would appreciate any sort of help or hints!
If you go to Customize > Tasks > Task Fields, you will see two such fields, 'Name' and 'Related To'.
These are polymorphic fields and can relate to more than one type of object.
Specifically the 'Related To' field, which has an API name of WhatID links to Account and many others.
In your trigger, you have to write code to get the Account whose matches the ID in the WhatID field. You then have to update it and issue an update DML Statement.
You said you need an after insert trigger. But that works only if a new task is inserted (created). In your case the Purpose field is updated, so the event you have to use is the After Update event for tasks.
Hope this helps.
Regards,
Satish Kumar
Please mark my answer as a solution if it was helpful so it is available to others as a proper solution.
If you felt I went above and beyond, please give me Kudos by clicking on the star icon.
what's your status on this project? sounds interesting for me...