You need to sign in to do that
Don't have an account?
uma52551.3972270309784705E12
Create Task on Case object
Hi All,
Please correct my trigger. When a case is created it should insert a task.The "Assigned to"(Owner) field should be the lookup to Account that is on the case and from there to another custom object called underwriters inside this field called UW_User__c.
trigger TriggerToInsertTask on Case (after insert) {
List<RecordType> rdType = [Select Id from RecordType where SObjectType = 'Case' and Name = 'Bintech' Limit 1];
List<Case> ca = [Select Id,Type,RecordType.Name,Account.Commercial_Lines_Underwriter__r.UW_User__c,CreatedDate From Case Where RecordType.Name = 'Bintech' and Type = 'Loss Runs' Limit 1];
List<Task> tk = new List<Task>();
for(Case c: Trigger.new){
Task ts = new Task();
if(c.Account!=NULL && c.Policy__c!=NULL &&c.RecordType.Name=='Bintech')
ts.WhatId = ca[0].Id;
//ts.RecordType.Id = '012E000000022ZQ';
ts.Subject = 'Loss Run Case Follow-Up';
ts.Priority = 'Medium';
ts.ActivityDate = Date.valueOf(ca[0].CreatedDate)+7;
ts.OwnerId = ca[0].Account.Commercial_Lines_Underwriter__r.UW_User__c;
}
insert ca;
}
Thanks!
Please correct my trigger. When a case is created it should insert a task.The "Assigned to"(Owner) field should be the lookup to Account that is on the case and from there to another custom object called underwriters inside this field called UW_User__c.
trigger TriggerToInsertTask on Case (after insert) {
List<RecordType> rdType = [Select Id from RecordType where SObjectType = 'Case' and Name = 'Bintech' Limit 1];
List<Case> ca = [Select Id,Type,RecordType.Name,Account.Commercial_Lines_Underwriter__r.UW_User__c,CreatedDate From Case Where RecordType.Name = 'Bintech' and Type = 'Loss Runs' Limit 1];
List<Task> tk = new List<Task>();
for(Case c: Trigger.new){
Task ts = new Task();
if(c.Account!=NULL && c.Policy__c!=NULL &&c.RecordType.Name=='Bintech')
ts.WhatId = ca[0].Id;
//ts.RecordType.Id = '012E000000022ZQ';
ts.Subject = 'Loss Run Case Follow-Up';
ts.Priority = 'Medium';
ts.ActivityDate = Date.valueOf(ca[0].CreatedDate)+7;
ts.OwnerId = ca[0].Account.Commercial_Lines_Underwriter__r.UW_User__c;
}
insert ca;
}
Thanks!
Review all error messages below to correct your data.
Apex trigger TriggerToInsertTask caused an unexpected exception, contact your administrator: TriggerToInsertTask: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Assigned To ID: owner cannot be blank: [OwnerId]: Trigger.TriggerToInsertTask: line 18, column 1