You need to sign in to do that
Don't have an account?
Austin Johnsey
Trigger template for updating task field from field on related object
I have an identical custom field (Site_ID__c) on leads, contacts, opportunities and tasks. When a task is created and related to one of these objects, I would like a trigger that would update the field on the task from the field on the related object. Does anyone have a code template for listing the whatids, determining the object type and then specifying the custom field to update? Ideally, the code would repeat the process for all 3 possible objects in this scenario.
Hope below code will help you ..
String account_prefix = Schema.SObjectType.Account.getKeyPrefix();
String task_whatid = task.WhatId;
if(task_whatid.startsWith(account_prefix)){ // Means Id is of Account Type