trigger OpptyLineItem on OpportunityLineItem (after insert, after update) {
if(Trigger.isAfter) {
if(Trigger.isInsert && Trigger.isUpdate) {
for(OpportunityLineItem o : Trigger.new) {
try {
Contract__c listCont = [SELECT id, LastModifiedById, CreatedDate FROM Contract__c WHERE Opportunity__c = :o.OpportunityId LIMIT 1];
Task todo = new Task();
todo.RecordtypeId = '0125D000000qwClQAI';
todo.OwnerId = listcont.LastModifiedById;
todo.Subject = 'Sync Contract';
todo.Priority = 'Normal';
todo.WhatId = listCont.id;
todo.Status = 'Not Started';
todo.IsReminderSet = True;
insert todo;
} catch(Exception e) {
System.debug(e.getMessage());
}
try {
Proposal__c listProp = [SELECT id, LastModifiedById, CreatedDate FROM Proposal__c WHERE Opportunity__c = :o.OpportunityId ORDER BY CreatedDate DESC LIMIT 1];
Task todo2 = new Task();
todo2.RecordtypeId = '0125D000000qwClQAI';
todo2.OwnerId = listProp.LastModifiedById;
todo2.Subject = 'Sync Proposal';
todo2.Priority = 'Normal';
todo2.WhatId = listProp.id;
todo2.Status = 'Not Started';
todo2.IsReminderSet = True;
insert todo2;
} catch(Exception e) {
System.debug(e.getMessage());
}
}
}
}
}
I want to create a task whenever I add or modify an opportunity product. That's why I'm using a trigger, but when an opportunity product is added or modified, a task is not created. Is there a problem with my code?