• Matt Emara
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi All,

I am writing a trigger that creates an Invoice Item based on a selection of services.

The trigger works well if the selection is made on record creation but if it is being updated it doesn't fire.

Here is the code:

trigger PickupService on Invoice__c (after Insert) {
    List <Invoice_Item__c> Item = new List <Invoice_Item__c>();
    for (Invoice__c Inv: Trigger.new)
    {
        if (Inv.Pickup_Service__c == True)
        {
            Invoice_Item__c I = new Invoice_Item__c();
            I.Invoice__c = Inv.Id;
            I.Quantity__c= 1;
            I.Product__c = '01t4B000000Rnir';
            I.Service_Fee_Type__c = 'Room Service- Pickup';
            I.Item_Price__c = 15.00;
            
            Item.add(I);           
            
        }
        insert Item;
    
    }
}

When I add 'after update' the trigger fails to fire and the original record fails to create. I've tried doing this using Process Builder as well and the same issue occurs.

The error I email I get is very long but the final error states: CUMULATIVE_LIMIT_USAGE_END
There are other Apex Classes and Triggers build into the org is it possible that because of the existing code there are too many queries being processed?

I've tried building the same functionality in a different Sandbox that is blank and it is working fine. Any ideas?

Thanks for your help.
Hi All,

I am writing a trigger that creates an Invoice Item based on a selection of services.

The trigger works well if the selection is made on record creation but if it is being updated it doesn't fire.

Here is the code:

trigger PickupService on Invoice__c (after Insert) {
    List <Invoice_Item__c> Item = new List <Invoice_Item__c>();
    for (Invoice__c Inv: Trigger.new)
    {
        if (Inv.Pickup_Service__c == True)
        {
            Invoice_Item__c I = new Invoice_Item__c();
            I.Invoice__c = Inv.Id;
            I.Quantity__c= 1;
            I.Product__c = '01t4B000000Rnir';
            I.Service_Fee_Type__c = 'Room Service- Pickup';
            I.Item_Price__c = 15.00;
            
            Item.add(I);           
            
        }
        insert Item;
    
    }
}

When I add 'after update' the trigger fails to fire and the original record fails to create. I've tried doing this using Process Builder as well and the same issue occurs.

The error I email I get is very long but the final error states: CUMULATIVE_LIMIT_USAGE_END
There are other Apex Classes and Triggers build into the org is it possible that because of the existing code there are too many queries being processed?

I've tried building the same functionality in a different Sandbox that is blank and it is working fine. Any ideas?

Thanks for your help.