I have a task trigger
public static void CustomObject_Email_rec_date_Upd(list<Task> lst_task){
list<Custom_Object_c> lst_ELE_Agg_Var = new list<Custom_Object_c>();
for(Task taskvar:lst_task) {
if(taskvar.Whatid !=null)
{
if(taskvar.Whatid.getSobjectType() == Schema.Custom_Object_c.SObjectType && taskvar.subject.contains('RE:')){
DateTime dT = System.now();
Date myDate = date.newinstance(dT.year(), dT.month(), dT.day());
Custom_Object_c ELE_Agg_Var = new Custom_Object_c();
ELE_Agg_Var.id = taskvar.Whatid;
// ELE_Agg_Var.Email_Received_Date__c = taskvar.createddate;
ELE_Agg_Var.Email_Received_Date__c = myDate;
ELE_Agg_Var.Read_Email__c = taskvar.WCT_Is_Read__c;
system.debug('+++++++++++=========='+taskvar.WCT_Is_Read__c);
lst_ELE_Agg_Var.add(ELE_Agg_Var);
}
}
Database.update(lst_ELE_Agg_Var,false);
}
}
Trigger:
if(trigger.isAfter && trigger.isUpdate){
WCT_Task_Trigger_Handler.Ele_Agrements_Email_rec_date_Upd(Trigger.new);
}
if(trigger.isAfter && trigger.isInsert){
WCT_Task_Trigger_Handler.Ele_Agrements_Email_rec_date_Upd(Trigger.new);
}
I am trying update Email receive date field and Read Email field in custom Object Whenever a task is created or updated.
I have received an email in Activity history and then Email receive date should update and when I open that Read Email field in Custom Object should be updated.
when we open email from Activity history Task trigger will not run? if not when will execute Task trigger to update fields?
Thanks in Advance
This is how we actually update task using this page:
<apex:page standardController="Task" >
<script src="/soap/ajax/29.0/connection.js"></script>
<script type="text/javascript">
if('{!Task.WCT_Is_Read__c}' == 'false'){
var tsk = new sforce.SObject("Task");
tsk.Id = '{!Task.Id}';
tsk.WCT_Is_Read__c = 'true';
var mobId = '{!Task.What.Id}';
var result = sforce.connection.update([tsk]);
var tskRecord = sforce.connection.query("Select Id,WCT_Is_Read__c from Task where what.id = '{!Task.What.id}' AND recordTypeId = '0121W000000gzDH' AND subject LIKE 'RE:%'");
//alert('tskRecord'+tskRecord);
var isMobUpdate;
var tskRecords = tskRecord.getArray('records');
var count = 0;
for(var i = 0; i < tskRecords.length; i++){
var tskRec = tskRecords[i];
if(tskRec.WCT_Is_Read__c == 'true'){
count++;
}
}
if(tskRecords.length == count){
// alert('Count matched');
isMobUpdate = 'update';
}
if(isMobUpdate == 'update'){
if("{!Task.WCT_Task_for_object__c}" == 'Pension_Request__c'){
var mob = new sforce.SObject("Pension_Request__c");
mob.Id = '{!Task.What.Id}';
mob.PR_Unread_Email_on_this_Request__c = 'false';
var mobresult = sforce.connection.update([mob]);
// alert('result'+mobresult);
}
}
// window.top.location='/'+'{!Task.Id}';
}
</script>
Can we update any custom object fields using this page? if yes, Can you please tell me how?