• Jessi Waldon
  • 0 Points
  • Member since 2016

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
  • 0
I am trying to have a trigger and trigger handler that create Credit Note Lines only once a Credit Note status is Posted. 

I believe my code needs to be beforeUpdate to avoid a validation issue if I try afterUpdate(that validation is unable to be turned off as it's managed package code)

Below is my code. Do you know how to avoid the recurssion issue?
protected override void beforeUpdate() { 

        System.debug('CreditNoteTriggerHandler afterUpdate()'); 




    private void insertCreditNoteLine(){ 

        List<blng__creditNote__c> creditNotes = (List<blng__CreditNote__c>)Trigger.new; 

        List<blng__CreditNoteLine__c> creditNoteLinesToInsert = new List<blng__CreditNoteLine__c>(); 

        for(blng__CreditNote__c c : creditNotes){ 

        if(c.blng__CreditNoteSourceAction__c == 'Manual' && c.blng__Status__c == 'Posted'){ 

                Valpak__c vpc = Valpak__c.getOrgDefaults(); 

                //String discountstring = vpc.ZVP_Discounts_Returns_Allowances__c; 

                //Id discountid = id.valueOf(discountstring); 

                blng__CreditNoteLine__c line = new blng__CreditNoteLine__c(); 

                line.blng__CreditNote__c = c.Id;  

                line.blng__StartDate__c = c.blng__CreditNoteDate__c;  

                line.blng__EndDate__c = c.blng__CreditNoteDate__c;  

                   line.blng__LegalEntity__c = c.blng__Account__r.ZVP_Franchise__r.ZVP_Legal_Entity__r.Id; 

                   line.blng__Subtotal__c = c.ZVP_Amount__c; 


               if(c.ZVP_Credit_Adjustment_Type__c == 'NSF Add Payment'){ 

                   line.blng__Product__c = id.valueOf(vpc.ZVP_Billing_AR_Clearing__c);  


               }Else if(c.ZVP_Credit_Adjustment_Type__c == 'Bad Debt Write-Off'){ 

                    line.blng__Product__c = id.valueOf(vpc.ZVP_Allow_for_Doubtful_Accounts_PC_Req__c);  


               }Else if (c.ZVP_Credit_Adjustment_Type__c == 'Exchange Rate - Reduce Amount Received'|| 

                     c.ZVP_Credit_Adjustment_Type__c == 'Intercompany Credit'){ 

                     line.blng__Product__c = id.valueOf(vpc.ZVP_Accrued_Intermarket_Fees_Payable__c);  


               }Else if (c.ZVP_Credit_Adjustment_Type__c == 'Misc Credit'|| 

                        c.ZVP_Credit_Adjustment_Type__c == 'Add Correct Payment'|| 

                        c.ZVP_Credit_Adjustment_Type__c == 'Go-Live Balance Reduction'||    

                        c.ZVP_Credit_Adjustment_Type__c == 'Finance Charge (CR)'||  

                        c.ZVP_Credit_Adjustment_Type__c == 'VBC Credit'){ 

                            line.blng__Product__c = id.valueOf(vpc.ZVP_Clearing_Account_Other__c);  


               }Else if(c.ZVP_Credit_Adjustment_Type__c == 'Barter/Direct Trade'){ 

                            line.blng__Product__c = id.valueOf(vpc.ZVP_Trade_Barter_Expense__c);  


               }Else if(c.ZVP_Credit_Adjustment_Type__c == 'Coupon/Discount'|| 

                        c.ZVP_Credit_Adjustment_Type__c == 'Sales Price Decrease'|| 

                        c.ZVP_Credit_Adjustment_Type__c == 'Refunds - Invoice'){ 

                                line.blng__Product__c = id.valueOf(vpc.ZVP_Discounts_Returns_Allowances__c);  


               }Else if(c.ZVP_Credit_Adjustment_Type__c == 'Collection Agency Fee Removed'){ 

                                line.blng__Product__c = id.valueOf(vpc.ZVP_Collection_Fees__c); //line.blng__Subtotal__c = c.ZVP_Amount__c; 


               }Else if (c.ZVP_Credit_Adjustment_Type__c == 'Sales Tax Adjustment'){ 

                                line.blng__Product__c = id.valueOf(vpc.ZVP_Sales_Tax__c); //line.blng__Subtotal__c = c.ZVP_Amount__c; 




                                }//if manual 

         }//end for loop 

        if(creditNoteLinesToInsert.size() > 0) { 

            System.debug('creditNoteLinesToInsert: ' + creditNoteLinesToInsert); 

            insert creditNoteLinesToInsert; 



And here is my Trigger
trigger tgr_CreditNote on blng__CreditNote__c (before insert, before update, after insert, after update, before delete, after undelete) {
    new CreditNoteTriggerHandler().run();

Any help is greatly appreciated. I am trying to write test coverage and get this to my QA team soon.

I am updating a custom task (Milestone Tasks) status to completed. It is throwing an exception:

Review the following errors
CCMI.TaskConfiguration: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0Z46000003E4s2EAC; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CCMI.TaskConfiguration: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0Z46000003E95ZEAS; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = a0Z46000003E95Z) is currently in trigger CCMI.TaskConfiguration, therefore it cannot recursively update itself: [] (CCMI): [] (CCMI)

When I try to pull up the code I started with TaskConfiguration but it shows (hidden) in the dev console. Any help you can provide in trouble shooting this would be appreciated. 
Taking the Business Administration Superbadge Challenge and getting "Not yet complete... here's what's wrong: 
There was an unexpected error while verifying this challenge. Usually this is due to some pre-existing configuration or code in the challenge Org. We recommend using a new Developer Edition (DE) to check this challenge. If you're using a new DE and seeing this error, please post to the developer forums and reference error id: PZDVUQCP"

Thoughts on what to do?