You need to sign in to do that
Don't have an account?
Whitney Klein 10
How do I create an Apex Trigger to Update Account Fields from A Quick Action
Hello, I have made a quick action on my accounts tab that allows faster Log a Call. I have two fields on my account that I want to have updated with this quick call info. The fields are Last Sales Call Date (date of log a call) and Last Sales Call Description (description field from log a call).
I know I need to do this with a trigger as opposed to workflow rules but I have absolutely no experience with Apex. Any help is greatly appreciated!!
I know I need to do this with a trigger as opposed to workflow rules but I have absolutely no experience with Apex. Any help is greatly appreciated!!
trigger TaskTrg on Task( after insert, after update )
{
Map<Id, Account> accountsToBeUpdated = new Map<Id, Account>();
for( Task t : trigger.new )
{
if( trigger.isInsert
|| ( trigger.isUpdate
&& ( trigger.oldMap.get( t.Id ).ActivityDate != t.ActivityDate
|| trigger.oldMap.get( t.Id ).Description__c != t.Description__c )
)
)
{
if( t.WhatId != null && String.valueOf( t.WhatId ).startsWith( '001' ))
{
Account acc = new Account( Id = t.WhatId );
acc.Last_Call_Date__c = t.ActivityDate;
acc.Last_Call_Description__c = t.Description__c;
accountsToBeUpdated.put( acc.Id, acc );
}
}
}
if( accountsToBeUpdated.values().size() > 0 )
update accountsToBeUpdated.values();
}