everyone!
I just started learning APEX last week, and I'm now learning APEX Triggers. I need help for the task below.
Overview:
- I created a new field in Contact Object: "Details Completed" (checkbox)
- I also created an APEX trigger to make a new task: follow up contact if details are not completed (Details Completed is uncheck) // this trigger works fine
Problem: Now, I need to make a new trigger if follow up task (from above) is completed (status=completed), but "Details Completed" in Contact Object is still unchecked: New task is to make a second follow up reminder to contact to provide details
I'm trying to access the field Details_Completed__c from Contacts but it seems like I'm unable to, is there a way I can do this? Here's the code that I made:
trigger statusCompletedTrigger on Task (after update) {
if(trigger.isUpdate){
List<Task> taskList = new List<Task>();
List<Task> task = [select id, subject, whoid, status from task where id in :trigger.new order by createdDate desc];
List<Contact> con = [Select Id, LastName, Document_Verified__c from Contact];
for (task updateTask: task){
if (updateTask.status == 'completed'){
if (con.Document_Verified__c == false){
taskList.add(new Task(
Subject = 'Follow up again with ' + updateTask.whoId,
ActivityDate = system.today().addDays(7),
Priority = 'High', whatId=updateTask.whoId)
);
}
if (taskList.size()>0) {
insert taskList;
}
}
}
}
}
Kindly help me with my concern above, also, please feel free to comment on the points where I can improve, I know the code I've created above have many flaws. Thank you in advance everyone!