0
votes

I need to write a trigger to pre-fill the value of "Related to: company" field ( if it is null only) on the task object based on the "related to: contact" field value before submitting the record. Please help me how can I achieve this.

Thanks, Shweta

1

1 Answers

0
votes

trigger TaskTrigger on Task (after update) { for(Task newTask : Trigger.New){ // Task.WhoId != null ----Checks Contact is null or not // ((string)Task.WhoId).startsWith('003') ----Checks Task is related to Contact // Task.WhatId == null ----Checks the related to field is null or not if(Task.WhoId != null && ((string)Task.WhoId).startsWith('003') && Task.WhatId == null ){ // Add your code as per your needs. } } }