You need to sign in to do that
Don't have an account?
Apex Trigger to Populate Date Field
Hello,
I would like to write an Apex Trigger on the Task Object that will populate a date field on the Account Object with the Created Date of the Last Activity With a Status of Completed and a Subject of Completed Call.
Anyone have any ideas on how to approach this.
I would like to write an Apex Trigger on the Task Object that will populate a date field on the Account Object with the Created Date of the Last Activity With a Status of Completed and a Subject of Completed Call.
Anyone have any ideas on how to approach this.
Good day.,
Thanks,
Balaji
All Answers
Hey Chad,
It's me again :). Have a question, do you want the max of created date to be on the account or the date of task that is current set to completed?
Either way it would be trigger on task, where you verify if the completed status task belongs to Account (T.whatId prefix should be 001), and process them based on your answer to my above question.
Thanks,
balaji
And It's nice to see you again lol.
If you want all the tasks that belongs to children of a particular account to be accounted for, then you might need to use "AccountI" field on the Task and process it accordingly.
Assuming Recent_Completed_Activity__c is the api name of the date field on account
Hope it helps,
Thanks,
Balaji
select max(createdDate)MaxCDate,WhatId From Task Where WhatId IN : AccountIdSet and Status='Completed' and Subject='Completed Call' Group By WhatId
forgot to include group by clause in the previous post.
Thanks,
balaji
Sorry about the late response. I was out of the office. Alright so I tried your code, and I changed task_Record to just T. It makes it alittle easier on myself. But anyways. Heres what i have now:
Im receving the following error: Method does not exist or incorrect signature: [Id].statsWith(String) at line 8 column 12
and coming to the naming I agree that shorter var names looks better, but when debugging in future by any person other than you, if you can leave them a clue what that variable is about, they can close the deal easily than guessing what the variable does :).
Hope it helps.
Thanks,
Balaji
Try this
Try this version:
Try this and let me know if you see any more errors
Invalid initial expression type for field Account.Id, expecting: Id at line 15 column 38
Forgot to type cast the id and date values, you can try this final version :)
Good day.,
Thanks,
Balaji
I greatly appreciate all the help!
I even added another completed call and then tried to delete it thinking maybe it wouldn't delete only because there wasnt another record to populate the field but it still gave me the error. Any thoughts?
I know I'm so needy sometimes lol.