You need to sign in to do that
Don't have an account?
uHaveOptions
Apex Trigger on Activity Subject help
Hello Team,
I have 2 sample subject when an activity is being created.
Sample 1: Manually create a call log and the word "Call" will automatically be in the subject.
Sample 2: When we do a "click to call" and it will automatically create a call log with "Call 12/29/2015 14:18:23 - Outbound" in the subject. where date and time of course is based on the time called.
I have an Apex trigger but unfortunately it only work when a call log is manually entered. What code should I insert for the second sample to work?
Thanks in advance
I have 2 sample subject when an activity is being created.
Sample 1: Manually create a call log and the word "Call" will automatically be in the subject.
Sample 2: When we do a "click to call" and it will automatically create a call log with "Call 12/29/2015 14:18:23 - Outbound" in the subject. where date and time of course is based on the time called.
I have an Apex trigger but unfortunately it only work when a call log is manually entered. What code should I insert for the second sample to work?
Thanks in advance
trigger CallDate on Task (after insert, after update, after delete) { Set<Id> con_set = new Set<Id>(); List<Contact> con_list = new List<Contact>(); for( Task T: Trigger.new ) { if(String.valueof(T.whoid).startsWith('003') && T.Status=='Completed' && T.Subject=='Call' ) { con_set.add(T.whoid); } } for(AggregateResult aggregateResult:[SELECT max(createdDate)MaxCDate,whoid FROM Task WHERE whoid IN: con_set AND Status ='Completed' AND (subject LIKE 'call%' OR subject LIKE 'outbound%') group By whoid]) { con_list.add(new Contact(Id=(id)aggregateResult.get('whoid'),Last_Call__c=date.valueof(aggregateResult.get('MaxCDate')))); } try { if(con_list !=null && con_list.size()>0) { update con_list; } }Catch(Exception e){ system.debug('Exception ***'+e.getMessage()); } }
It sounds like you would need to do a before trigger that would check to see if the task is the right type, and if so create a list of related contacts to get the My_Last_Call_Date__c from. Then loop again and and if the Task has a related contact, set the Task's subject to append the My_Last_Call_Date__c to the end. Since it is a before trigger, you won't need to do an explicate update call to set the new subject text