I have this code for a trigger, that according to my logic, should break on the second run, given an if statement I setup, but I'm still getting an error related to maximum trigger depth. Here is my trigger:
trigger OppProductRollupTriggers on OpportunityLineItem (after insert,after update) {
List<OpportunityLineItem> allPLI = new List<OpportunityLineItem>();
allPLI = [SELECT Id,Name,OpportunityId,Opportunity.Custom_Product__c,Quantity,Product2.Family from OpportunityLineItem WHERE ID IN:Trigger.newMap.keySet()];
System.debug(allPLI);
for ( OpportunityLineItem oli : allPLI) {
IF(oli.Name.contains('P1') || oli.Product2.Family.contains('Fam1') || oli.Product2.Family.contains('FAM2') || oli.Name.contains('P2')){
IF(oli.Opportunity.Custom_Product__c ==FALSE)
{
oli.Opportunity.Custom_Product__c= TRUE;
update oli;
}
else{
return;
}
}
}
}
The line I believe should break the loop, is the one that says if the Custom_Product__c == FALSE, then do the update, if the update was already done(meaning it will be True, just return. Any ideas why I'm still getting an error?