You need to sign in to do that
Don't have an account?
Help Creating a Trigger to Copy Values from a Task to Custom Object
Hi,
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 : Trigger.new) {
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;
}
vehToinsert.add(ct);
}
}
try{
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.
Regards
Salesforce Adv Devloper.