After some problems with outstanding payments, José asks Linda to automate the sent out of dunning emails. He specifies that he wants the dunning emails to be sent automatically, at the right date and time, to the right people, and about the right invoices according to the defined business needs (exceptions, frequency, etc.).

A bit overwhelmed by this demand, Linda asks Vijay again to help her with this configuration.
Fields available in the package
Here are the fields that they find concerning automatic dunning on the Invoice objet:
Automatic dunning - Checkbox: checked by the scheduled apex class MarkInvoiceForAutoReminder. The processes that we explain in the next article are triggered - among others - by this checkbox.
Last Dunning Date - Date: field that is filled out by the process that will be created by you to keep the date of the last dunning email sent out.
Term - Date: maximum deadline for the payment of the invoice
Payment Due on - Date: date when the next payment is expected
Follow-Up Level - Picklist: You can add levels if you want or use less:
R0: no incident
R1: 1st email sent
R2: 2nd email sent
R3: 3rd email sent (last reminder before formal notice)
R4: formal notice
These fields represent the minimum to configure the automatic dunning process.
In order to adapt the dunning process to the needs of the company, additional fields need to be created. Vijay and Linda are talking with the accounting department to define the correct dunning conditions.

Additional fields to create for the dunning process
In order to make the dunning process work, please add all these fields.
IMPORTANT: Formulas, descriptions and help texts are to be adapted to your business context / need. For each condition in this article, please ask yourself: is it relevant to your business? otherwise adapt it or remove it.
Steps
1. Go to Setup > Object Manager > OBJECT ACCORDING TO THE FIELD YOU WANT TO CREATE
2. Click on Fields & Relationships
3. Click on New
4. Follow the wizard and add the information ACCORDING TO THE FIELD YOU WANT TO CREATE
For more details, please read these trailhead articles:
Input Fields
Here is the list of input fields to create, for more information, click on the links:
Formula Fields
Then we proceed to the configuration of the formula fields.
Note: When creating the formula fields, you may receive this type of error message:
The compiled formula is too large to be executed (9,501 characters). Maximum size of 5,000 characters (Associated field: Formula)
If your formulas are very complex or reference other formulas with many conditions, you can also use processes to work around the limits of Salesforce. We will show examples in the next chapter.
Here is the list of formula fields to create, for more information, click on the links:
Note: To avoid problems when saving formulas, be sure to:
(1) follow the order in which they were created,
(2) pay attention to the field name, replacing with letters (e.g., Field label: Follow-up Intensity > Field name suggested by Salesforce: Follow-upIntensity, replace the _ with an e without an accent).
The fields in detail
Here are the sample formulas and information for configuring the fields.
Reminder: Formulas, descriptions and help texts are to be adapted to your business context / need. For each condition in this article, please ask yourself: is it relevant to your business? otherwise adapt it or remove it.
Do not remind before the
Field Name: Do_not_remind_before_the
Object: Account
Data Type Date
Allows you to record the date (included) until which no reminder should start.
Taken into account by the field Do not remind on the Invoice object.
Here is the result for Cloud Kicks :
Dunning Intensity
Nom du champ : Dunning_Intensity
Object: Invoice
Data type: picklist
Allows you to configure the desired intensity of the dunning process in order to vary the frequency of reminder emails. You may wish that a client is reminded again within a shorter laps of time, thus you will choose a higher intensity.
List values:
Neutral - I0 (by default)
Emphasized - I1
Insistent - I2
Here is the result for Cloud Kicks:

Field Name: Payment_Date
Based on those packaged fields:
Packaged fields might have french API names. | Formula example: IF(ISBLANK(sofactoapp__R_glement_attendu_le__c), |
Here is the result for Cloud Kicks:
Do not remind |
Field Name: Do_not_remind
| Formula example: |
Here is the result for Cloud Kicks:
Contact OKField Name: Contact_OK
Note: You may have already created this field during the previous configuration | Formula example: |
PDF OKField Name: PDF_OK
Note: You may have already created this field during the previous configuration Automation: Sent out of invoice PDF via email. The formula is based on the packaged fields
Here is the result for Cloud Kicks: | Formula example: |

Dunning Reference DateField Name: Dunning_Reference_Date
Reminder: The Payment Date corresponds to the Term or Payment Due on if this field is not blank. | Formula example: IF(Payment_Date__c-sofactoapp__Date_derniere_relance__c<=0, sofactoapp__Date_derniere_relance__c, Payment_Date__c) |

Field Name: Automatic_dunning_exception
The exceptional cases of the proposed formula (as an example):
The formula is based on these packaged fields:
| Formula example: |
Here is the result for Cloud Kicks:
Automatic dunning exception (text)Field Name: Automatic_dunning_exception_text
| Formula example: |
Here is the result for Cloud Kicks:
Field Name: Automatic_dunning_anomaly
The anomalies defined in the proposed formula:
| Formula example: |
Here is the result for Cloud Kicks:
Automatic dunning anomaly (text)Field Name: Auto_relance_anomalie_texte
| Formula example: |
Here is the result for Cloud Kicks:
Dunning Frequency Field Name: Dunning_Frequency
Calculation of the frequency by using this formula:
Note: According to the conditions specified in the fields Automatic dunning exception et Automatic dunning anomaly, it might not be possible to take into account the two conditions in the formula Dunning Frequency without getting an error message. Let's see how to configure a process with process builder as a workaround. | Formula example: |

Next Dunning Date
Field Name: Next_Dunning_Date |
|
Allows you to define the date on which the next dunning email will be sent, thanks to Dunning Reference Date plus Dunning Frequency.
Left blank, if Automatic dunning anomaly / exception equals true.
Note: In the Blank Field Handling section select the value Treat blank fields as blanks in order to leave the Next dunning date blank, if the Dunning Frequency is blank.

Here is the result for Cloud Kicks:

Field Name: Automatic_dunning_condition
Note: According to the conditions specified in the fields Automatic dunning exception et Automatic dunning anomaly, it might not be possible to take into account the two conditions in the formula Dunning Frequency without getting an error message. Let's see how to configure a process with process builder as a workaround. | Exemple de formule : |
Make the fields available on the invoice page layout
After the creation of the fields, we will modify the display of these fields on the subject of the invoice.
Steps
Go to Setup > Object Manager
Click on the Invoice Object
Click on Page Layout and open the page layouts your are currently using in your org.
Drag and drop all the fields that we created before into the Dunning section :

5. Click on Save.
Now that the fields are available on the invoice, we will take care of the fields that we could not save before.

