You need to sign in to do that
Don't have an account?
Code+1
Trigger - Update Task field based on Case field
Hi Team,
I have a custom field on task object.
Whenever, there is a change in Case custom field, i would like to update the custom field in task.
Please let me know, to achieve it through trigger ..
I have a custom field on task object.
Whenever, there is a change in Case custom field, i would like to update the custom field in task.
Please let me know, to achieve it through trigger ..
Trigger.newmap.get(child.WhatId).customfield to get value of custom field on case
All Answers
Query for tasks related to that case and update the value.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers.htm?search_text=triggers
Thanks for your response.
I want to update the 'customfield' in task, when ever case is created / edited based on one custom field in case.
Please check the below code and help me out.
trigger XXXX on Case (after insert, after update){
List<Task> tskrecords = [Select Id, customfield, WhatId from Task where WhatId IN : Trigger.newMap.keySet()];
for(Task child :tskrecords){
if(trigger.isInsert && child.WhatId.customfield == '1234'){
child.customfield = '0000';
}
else if(trigger.isUpdate && child.WhatId.customfield == '1234'){
child.customfield = '0000';
}
}
if(tskrecords.size() > 0)
update tskrecords;
}
Trigger.newmap.get(child.WhatId).customfield to get value of custom field on case
please let me know, how to traverse from task to case custom field to check for the condition.
Trigger.newmap.get(child.WhatId).customfield to get value of custom field on case