简体   繁体   English

Apex触发器根据与联系人的相关联系来更新任务对象上与公司相关的字段的值(如果仅为空)

[英]Apex Trigger to update the value of Related to company field ( if it is null only) on the task object based on the related to contact

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 谢谢,Shweta

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. 在Task上触发TaskTrigger(更新后){for(Task newTask:Trigger.New){// Task.WhoId!= null ----检查Contact是否为null // //((string)Task.WhoId).startsWith( '003') ----检查任务是否与联系人 // Task.WhatId == null ----检查相关字段是否为null if(Task.WhoId!= null &&((string)Task。 WhoId).startsWith('003')&& Task.WhatId == null){ //根据需要添加代码。 } } } }}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM