You need to sign in to do that
Don't have an account?
Brenda Frambes 10
Create trigger to update custom object fields when a task is Opened
I have created a custom object Project__c. When a record is created on this object a series of Tasks are created. As tasks are closed other tasks are opened. I would like to update two fields on Project_C with the most recent Open Task. The field names on the Object are: Stage__c and Sub_Stage__c, the fields on the tasks are: Project_Stage__c and Project_Sub_Stage__c
So when a Task status changes to Open,
Stage__C = Project_Stage__c
Sub_Stage__C = Project_Sub_Stage__C
I'm trying to learn APEX to be able to do this myself but my skills aren't up to speed for this. Any help would be GREATLY appreciated. Thank you
So when a Task status changes to Open,
Stage__C = Project_Stage__c
Sub_Stage__C = Project_Sub_Stage__C
I'm trying to learn APEX to be able to do this myself but my skills aren't up to speed for this. Any help would be GREATLY appreciated. Thank you
trigger updateAccountOpenTask on Task (before update) {
List<Project__c> projectList = new list<Project__c>();
for(task taskRecord : trigger.new){
if(Trigger.oldMap.get(taskRecord.Id).Status == 'Closed') {
If(Trigger.newMap.get(taskRecord.Id).Status == 'Open'){
for(Project__c proj : [Select Id, Stage__c, Sub_Stage__c from Project__c where Id =: taskRecord.Project__c]){
proj.Stage__c = taskRecord.Subject;
proj.Sub_Stage__c = taskRecord.Subject;
projectList.add(proj);
system.debug('***********'+projectList);
}
}
}
}
if(!projectList.isEmpty()){
update projectList;
system.debug('***********'+projectList);
}
}
You can add the condition to find recentlu updated task
Let me know if this helps.