function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Help Creating a Trigger to Copy Values from a Task to Custom Object



I'm new to creating triggers and I've been using the posts on this board to help me along but now I'm stuck. Any help would be greatly appreciated.


I'm trying to create a trigger for a specific type of task so when that task is updated it updates the fields on the custom object that has an Email Alert.


Here's my code:


trigger QualityTaskEmailAlertTrigger on Task (after insert) {

List <Custom_Task__c> vehToInsert = new List <Custom_Task__c> ();
for(Task t : {
if (t.Type == 'Maintenance - Quality'){
Custom_Task__c ct = new Custom_Task__c ();
ct.OwnerId = t.OwnerId;
ct.CreatedById = t.CreatedById;
ct.LastModifiedById = t.LastModifiedById;
ct.Id = t.Id;
ct.Subject__c = t.Subject;

upsert vehToinsert;
} catch (system.DmlException e){
system.debug (e);


ct.CreatedById = t.CreatedById;
ct.LastModifiedById = t.LastModifiedById; are the read only field so you can not update the value of createdbyid or LastModifiedByid. If you want to copy these field value please create the custom field and then copied the value in these field.



Salesforce Adv Devloper.