Skip to content

How to allow creating invoices for testing purposes?

With custom test scenarios that require invoices to be created, JustOn shows the following error:

ONB2.BillON.ValidationException: Please use the InvoiceBuilder to create Invoice__c sObjects!

To circumvent this error and execute the test as intended, you must deactivate the triggers on invoices and invoice line items. To do so, add the following code at the beginning of your test code:

insert new List<ONB2__TriggerSettings__c>{
    new ONB2__TriggerSettings__c(
        Name = 'InvoiceBeforeInsert'
    ),
    new ONB2__TriggerSettings__c(
        Name = 'InvoiceBeforeUpdate'
    ),
    new ONB2__TriggerSettings__c(
        Name = 'InvoiceLineItemBeforeInsert'
    ),
    new ONB2__TriggerSettings__c(
        Name = 'InvoiceLineItemBeforeUpdate'
    )
};