You need to sign in to do that
Don't have an account?

Help with trigger to update custom object based on task completion
Hello,
I am hoping to get a trigger that will update a custom object checkbox and date field when a task is marked as complete.
The task is generated by a detail object and I want the master object to be updated when the task is complete.
Basically, there is an object called Position Posting which is the master object. The detail object, Job Application, is triggering the task. I would love for the trigger to update the master record, Position Posting, when the task is marked as complete. If that doesn't work, I could make it work for it to update the detail object, Job Application, instead.
Could anyone help with a trigger? I am totally new to coding so if someone could bold the areas where I need to plug in our own object/field names, that would be helpful.
Thank you for your help!!!
I am hoping to do this for a few different tasks if the code is able to be customized accordingly.
Following code might be usefull for you. Modify it as per your requirement.
String position_prefix = Schema.SObjectType.Position__c.getKeyPrefix();
Set<Id> positionId = new Set<Id>();
for(Task tsk : Trigger.new){
if(((String)tsk.WhoId).startsWith(position_prefix) && tsk.Status == 'Completed'){
positionId.add(tsk.whatId);
}
}
List<Position__c> positionList = [Select Id From Position__c]; //add rest of field on which you want to work on.
for(Position__c pos : positionList){
pos.tsk_completed__c = true;// what ever field you have created on Position object
pos.Completed_Date__c = System.now(); //what ever field you have created if it is data time type. if it is of type date then use System.today()
}
update positonList;
Hope this code will helps you.
Thanks,
Gajanan