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
AMalenaAMalena 

Set date on Account when (phone call) Task is created/saved.

All I want to do is record a date onto the Account record when a Task is created of Activity Type "Phone Call", that's it.  Unfortunately my experience level with Trigger programming is very low still and my workload is killing my efforts to go through the video training on our Premier support plan.

Anyone have a simple trigger mechanism that will do this?  I could probably write 80% of it, but the actual opening-and-linking to the Task and Account databases is my issue.  Stamping the date after verifying the Activity Type is a no-brainer.   :-/    I can't seem to find a good resource of Trigger code samples on the web.

Thanks for any help anyone can give...   I've been pretty sidetracked with tasks today, and threw together the below code in text editor which I am sure is not complete/correct yet, just as a reference.  :-/

 

 

trigger PiggybackTriggerTasks on Task (after insert) {

    List<Task> listTask = new List<Task>();
    List<Id> listAccountId = new List<Id>();

    if ( trigger.isInsert ) {

        for(Task thisTask: trigger.new) {

            if ( thisTask.Activity_Type__c == 'Phone Call' ) { listAccountId.add(thisTask.What); }

        }

        Account objAccount = mapIdAccount.get(thisAccountId);

        thisAccount.Last_PhoneCall_Activity__c = thisTask.ActivityDate

    }

}

SanchSanch

Don't use list, use set to add the account id's that you want to update. Then query those account records and update that field that you watn to set and do a bulk update at the end. 

AMalenaAMalena

Thanks for the tip.  It's just foreign enough at my skill level to confuse me, but I'm hopeful to figure it out as I actually test this code either today or Monday.  ;-)