Invoices issuance

Prev Next

With the invoices generation now automated, Linda wants to set up a process to issue them automatically. Vijay explains how to do that.


In order to prepare the configuration, Linda reads again this trailhead module:

Now they are looking at the automation configuration.

Trigger conditions on the invoice object


The automatic issuance from the invoice object is based on these three fields:

  • Automatic issuance

  • Automatic issuance condition

  • Automatic issuance exception

Note: The formulas in this table are given as an indication: Please customize the formulas according to your business needs. If you don't need to define exceptions or conditions you can simplify the process.
 

Auto issuance
This check box is used by the issuance process. It is already part of the package.

 

Auto issuance condition
This formula field identifies the invoices that need to be treated by the process. 
If the box is checked, an invoice is issued.
In our example we would like to issue the invoice, if: 

  • The invoice is not falling into the condition of an exception

  • Status = Draft

  • “Invoice Date” is inferior or equal to today

The formula is based on these fields:

  • Automatic issuance exception

  • Draft Invoice (packaged formula checkbox)

  • Invoice Date (sofactoapp__Date_de_facture__c/ packaged date field)

Please adapt the condition due to your business needs.

AND(Automatic_issuance_exception__c = FALSE,
sofactoapp__IsDraft__c,
sofactoapp__Date_de_facture__c <= TODAY())

Auto issuance exception
This formula field groups the exceptions, in which cases the issuance of invoices should not take place.
If the box is checked, the invoice is not taken into account by the process.  
In our example, the invoice is marked as an exception, if: 

Condition in our example:

  • Is the invoice linked to a quotation? 

The formula is based on this field:

  • Quotation (sofactoapp__Offre__c/ Packaged Lookup field)


Please adapt the condition due to your business needs.

 (ISBLANK(sofactoapp__Offre__c))

 Now that Linda understood the purpose of these fields, she can start the set up of these fields.

Setting up the fields needed for the automation

We recommend to read these trailhead articles, if you did not have occasion to train yourself on these topics:

The checkbox Automatic issuance is part of the package and thus is already present in the object.
Thus Linda configures only the check box and the two formula fields.


Since Automatic issuance exception refers to Automatic issuance condition, she has to sets up the fields in this order:

  • Formula field Automatic issuance exception

  • Formula field Automatic issuance condition

Procedure

1. Go to Setup > Object Manager > Invoice
2. Click on Fields & Relationships
3. Click on New
4. In Step 1: Choose the field type Formula
5. In Step 2: Choose the output type Checkbox and insert the field label Automatic issuance exception
6. In Step 3: Switch to the tab Advanced Formula and compose the formula that fits to your business needs.


Note: If you copy these formulas from the top of the article, please paste it into a text editor in order to take off the formatting of the text. It happens that the Formula editor does not accept copy pasted formulas due to the formatting.

7. Verify the formula syntax.
8. Insert a telling description and a help text that explains the field to the users.
9. In Step 4: Establish field-level security by checking the boxes of the profils you want to give the right to modify the field, according to your company security policies.
10. In Step 5: Instead of checking the box here, we recommend to go to each page layout of the invoice object you want to put the fields on, in order to put them manually in the right section.

Please repeat this procedure for the field Automatic issuance condition.

Note: In order to easily debug the process, if an invoice is not processed, because it is an exception, make life easier for users - and reduce your work - by putting conditions / exceptions in a non-technical language in the help text of these fields.

When the user understands why the invoice is an exception, he or she can modify the invoice to meet the conditions or at least understands why the invoice has not been processed.


Here you can see Linda's results:


Note: Don't forget to add the fields on your page layout so that users can check them, if there is a problem.

Control field in the Administration tab

Instead of creating a process in the process builder, we will select the condition in the Administration tab.


Procedure

1. Go to the App Launcher
2. Type Administration in the Quick find box
3. Open the Administration tab
4. Choose Auto issuance condition comme Control field for automatic emission of invoices.


  1. Click on the Confirm button.

Schedule the Apex job

If you want the invoice issuance process to start at a certain time, you have to set up a scheduled Apex job, here is the procedure of Salesforce for Scheduling Apex jobs.


Procedure

1. From Setup, enter Apex Classes in the Quick Find box, select Apex Classes, then click Schedule Apex.

2. Select the class: MarkInvoiceForAutoIssue

3. Specify how often the Apex class is to run.
4. Specify the start and end dates for the Apex scheduled class. If you specify a single day, the job only runs once.
5. Specify a preferred start time. The exact time the job starts depends on service availability.
6. Click Save.

Note:
(1) If you plan the Apex job during the day, remember that Frisbii users can still work on the invoices that already fall under the conditions. If the process wants to access an invoice which is in use, you will receive an error message and the process will stop.

(2) You can find the scheduled job afterwards under Setup > Environments > Jobs > Scheduled Jobs. If you want to modify the job, you have to delete it and schedule the Apex class again.

Testing approach

Congratulations! You configured the automation completely. Now let's not forget to test our setup.

Preparation

First, make sure you test on an invoice that meets the criteria, and therefore should be issued automatically.

For example in the case of Cloud Kicks:

  • The invoice is not falling into the condition of an exception

  • Status = Draft

  • “Invoice Date” is inferior or equal to today

and you have added the three fields on your page layout:

  • Automatic issuance

  • Automatic issuance condition

  • Automatic issuance exception


Procedure

  1. Open the Developer Console

  2. In the Debug menu > Open Execute Anonymous Window

  3. In the pop up window Enter Apex Code paste that expression:

sofactoapp.MarkInvoiceForAutoIssue 
autoissue = new sofactoapp.MarkInvoiceForAutoIssue(); Autoissue.execute(null);

 4. Click on Execute to run the script.

Was the test successful?

The test was successful, if:

  • your invoice is issued

  • the check box automatic issuance is checked

This is not the case?

Please verify:

  • On all test invoices, is the invoice date the same? It is possible that one date is in the future in relation to the invoice dates of other invoices. You can check the checkbox Regularize chronology problems on the Company name to avoid this problem. When issued, the invoice date will become the date of the last issued invoice.

  • Check your emails, as administrators receive process error messages by email.

  • The formulas of the fields:

    • Automatic issuance condition

    • Automatic issuance exception

  • On your test invoice:

    • The Automatic issuance condition checked?

      • No? > Compare your invoice with your set conditions

    • The checkbox Automatic issuance exception is checked?

      • Yes? > Modify your test invoice in order not to meet the exception criteria.

  • In the Administration tab, did you put the correct field ?

    • Please verify the procedure. 

Other possibilities if your tests are not conclusive :

  • The Show Discount check box is not checked on one or more invoices.

  • The Payment Method or Payment Term field has not been filled in on one or more invoices.

  • Other mandatory information is missing on one or more invoices (only for French corporate names).

  • One or more draft subscriptions are linked to one or more invoices. Please activate them.

Tip: To avoid chronology problems on the Invoice Date you can check the Regularize chronology issues check box. Invoices containing an invoice date prior to the last issued invoice date will be dated to today's date.


Important : The Regularize chronology issues option does not address invoices issued in the future. If an invoice has an invoice date later then today's date, the date will not be changed. To avoid this you can activate the validation rule Issue_impossible_in_the_future  (Emission_impossible_dans_le_futur) on the Invoice object.