6.1.6 Automate the Pre-Invoice Generation
It is now possible to automate pre-invoice generation using APEX which will run the batch job and create Pre-Invoices for Media Campaigns based on certain pre-defined criteria and following the payment criteria set out in the Media Campaign.Â
From version 2.118, you can also determine a recipient email address for the result email from the batch job. This is particularly useful for managing the invoicing of different legal entities within the same org. Â
Customers, who have the GenerateInvoiceBatch.cls
for Pre-Invoice Generation scheduled, need to reschedule it after the Release is installed in their org to use this function.
To find out more, please talk to your Account Manager about creating pre-invoices using APEX.
Create Pre-Invoices (using APEX)
Build your own way to create Pre-Invoices by using the APEX code. The global class ADvendio.GenerateInvoiceBatch can be used to start a batch job that will create Pre-Invoices for Media Campaigns.
Simple call
new ADvendio.GenerateInvoiceBatch().startBatch();
This will start the Pre-Invoice generation for all Media Campaigns with the Bill Me checkbox = true and the following fields set:
Payment Interval
Payment Start
Payment Due to
Advanced call
ADvendio.GenerateInvoiceBatch generateInvoiceBatch = new ADvendio.GenerateInvoiceBatch();
generateInvoiceBatch.query = 'SELECT Id, Name FROM ADvendio__MediaCampaign__c WHERE ADvendio__LegalEntity__c = \'a1EA000000FfEBSMA3\'AND ADvendio__BillMe__c = True';
Database.executeBatch(generateInvoiceBatch, 1);
This example will create Pre-Invoices for all Media Campaign with Legal Entity 'a1EA000000FfEBSMA3' where Bill Me is set to True.
You can change the query WHERE condition as you like (see Salesforce SOQL documentation). Linking variables using a colon (:) will not work, because the query will be executed in a different context.
Email Recipients
ADvendio.GenerateInvoiceBatch generateInvoiceBatch = new ADvendio.GenerateInvoiceBatch();
generateInvoiceBatch.query = 'SELECT Id, Name FROM ADvendio__MediaCampaign__c WHERE ADvendio__LegalEntity__c = \'a1EA000000FfEBSMA3\'AND ADvendio__BillMe__c = True';
generateInvoiceBatch.resultEmailAddress = 'mail1@advendio.com, mail2@advendio.com';
Database.executeBatch(generateInvoiceBatch, 1);
This example will create Pre-Invoices for all Media Campaign with Legal Entity 'a1EA000000FfEBSMA3' where Bill Me is set to True.
When the job is complete, the result email will be sent to mail1@advendio.com and mail2@advendio.com