You need to sign in to do that
Don't have an account?
Jacob Elliott 1
Apex Trigger to create new record throwing this error:execution of AfterInsert caused by: System.SObjectException: DML statement cannot operate on trigger.new or trigger.old ()
I am new to Apex and would really appreciate any help I can get! I have an Object called Interview and when a user creates an Interview Task with a record type of Interview, I want a new Interview Record to be created. When trying to save the new interview record, I get this error: "execution of AfterInsert caused by: System.SObjectException: DML statement cannot operate on trigger.new or trigger.old ():.
Below is my Code
Below is my Code
trigger CreateInterview on Task (after insert) { for (Task t : Trigger.new) { Interview__c i = new Interview__c(); i.CreatedById = t.OwnerId; i.Candidate__c = t.Candidate__c; i.Interview_Date__c = t.ActivityDate; i.Job_Position_Text__c = t.Job_Position__c; i.Hiring_Manager__c = t.Hiring_Manager__c; i.Hiring_Location__c = t.Hiring_Location__c; i.Hiring_Unit_Department__c = t.Hiring_Unit_Department__c; i.Id = t.Interview__c; i.Comments__c = t.Description; i.Name = t.Subject; i.Id = t.WhatId; insert t; } }
All Answers