Dunning: Creation of the process

Prev Next

Linda and Vijay set up all the fields needed for the automation of the dunning process.

Now they configure the process, including creating email templates, planning the Apex class, creating the process in the process builder and of course testing the entire configuration.


Vijay and Linda first create the Email templates.

Creation of an Email template for dunning emails

Linda asked her colleague Mary from the accounting service to join her in order to define the messages for the dunning emails.

Note:

(1) An email template needs to be provided for each follow-up level.

(2) Please create your own email templates. These are just inspirations and absolutely for reference only.


Procedure

1. Go to Settings, type template, and click Classic Email Templates.
2. Click on the link Create a new folder and name it Automatic Dunning.
3. Configure the folder according to your business needs and save it.
4. Click New Template
5. Choose the Text template type, and click Next.
6. Choose your created folder Automatic Dunning in order to store the template.
7. To make the template available for use, select the Available For Use checkbox.
8. Enter a name in Email Template Name like Reminder1
9. Insert a Subject and add fields thanks to the wizard, like

Reminder N°1 - Invoice N° {!sofactoapp__Factures_Client__c.sofactoapp__Reference__c}
  1. Copomes the Body of the message and add also fields thanks to the wizard, like

Dear sir or madam, 

Unless there is an error or omission on our part, we have not received your payment of the invoice N° {!sofactoapp__Factures_Client__c.sofactoapp__Reference__c} issued the {!sofactoapp__Factures_Client__c.sofactoapp__Date_de_facture__c} for the amount of {!sofactoapp__Factures_Client__c.sofactoapp__Amount_VAT__c} EUR, which fell due on {!sofactoapp__Factures_Client__c.sofactoapp__Ech_ance__c}.

We kindly ask you to proceed to its payment as soon as possible, and send you a duplicate of this invoice as an attachment.

If, moreover, your payment reaches us before receiving this letter, we would be grateful if you did not take it into account.

Thank you for doing what is necessary, and remaining at your entire disposal for any possible questions,

Your team of
{!sofactoapp__Factures_Client__c.sofactoapp__emetteur_facture__c}
  1. Save and please repeat these steps - despite for the creation of the folder - for each follow up level.

Linda and Mary created all of the follow-up email templates.

As Mary goes back to her office, Linda joins Vijay to continue with the configuration of the process.

Creating the email reminder automation flow

If you prefer flows to processes, here's how to trigger the Apex class using a process.

We will use the Apex MarkInvoiceForAutoReminder class to send reminder emails to the customer. It will then check the Auto reminder box, which will trigger the process we are about to configure.

Note: Now we will create a new flow dedicated to auto-reminders.

Procedure

1. Go back to Setup > Process Automation > Flows.

2. Click the New Flow button.

A - In the Flow window:

3. Choose the Record-Triggered Flow type.

Give it a descriptive name such as Frisbii - Invoice - Auto-reminder.

4. Select Auto-presentation.

You are now on the workflow creation canvas.

Enter a short but descriptive description, such as “Send reminder emails to customers.”

B - Select an object and specify the conditions:

5. Click on the space under “Workflow triggered by a record” that starts with “Trigger.”

6. For “Trigger the flow when,” select “A record is updated.”

7. For “Run the flow,” select “After the record is saved.”

8. Click Done.

9. Now click + Choose an object.

10. Search for and select Invoice.


11. In the “Search in fields...” area under Field, search for and select the auto-reset field.

12. Keep the operator set to “Equals” and enter True in Value.

13. Select the Only when a record is updated option to meet the requirements of the conditions in When to run the flow for updated records.

C - Creating variables:

14. In the left panel, click the New Resource button.

15. Select the Formula type.

16. Enter the following information:

  • API name: Formula_TemplateName

  • Description: Variable that gives the name of the template to use for the reminder.

  • Data type: Text

Formula to be adapted according to your needs:

CASE(TEXT({!$Record.sofactoapp__Langue__c}),
"France","FR",
"Anglais","EN",
"Espagnol","ES",
"Allemand","DE",
"FR")
&"_"&
TEXT({!$Record.sofactoapp__Niveau_de_relance__c})
&"_Reminder"

17. In the left panel, click the New Resource button.

18. Select the Formula type.

19. Enter the following information:

  • API Name: Formula_DunningLevel

  • Description: Variable that gives the next dunning level to use.

  • Data Type: Text

  • Formula to be adapted according to your needs:

CASE(TEXT({!$Record.sofactoapp__Niveau_de_relance__c}),
"R0","R1",
"R1","R2",
"R2","R3",
"R3","R4",
"R4")

D - Adding the email sending element:

20. Click on the circled plus sign to Add an element.

21. Select the Action item.

22. Search for the Send_Invoices_Emails action

Define the following information:

  • Label: Send reminder email

  • Description: Send the latest generated PDF of the invoice by email with a message tailored to the language and reminder level of the invoice.

  • Email template DeveloperName: Formula_TemplateName

  • InvoiceId: {!$Record.Id}

  • Optional:

    • BCC addresses

    • CC addresses

    • Org wide email address: {!$Record.sofactoapp__emetteur_facture__r.sofactoapp__Email__c}

    • Other addresses

    • Reply-to email address

    • Sender display name: {!$Record.sofactoapp__emetteur_facture__r.Name}

Please note: First declare all the email addresses you want to use as org-wide email addresses.

23. Click Done.

E - Prepare the invoice for the next reminder:

24. Click the small plus sign under the newly created action to Add an item.

25. Choose Update Records.

26. Enter the following information:

  • Label: Update invoice for next reminder

  • Description: Fill in the “last reminder date” field and uncheck the “auto reminder” field on the invoice to allow for a potential next reminder.

  • How to search for records to update their value: Specify conditions for identifying records, then define the fields individually.

  • Object: Invoice

  • In the “Filter Invoice records” area: Field: Id - Equal to - {!$Record.Id}

  • In the “Set field values on Invoice records” area:

    • Last reminder date - {!$Flow.CurrentDate}

    • Auto reminder - False

    • Reminder level - {!Formula_ReminderLevel}

27. Click Done.

28. Click Save in the top right corner.

29. Choose a meaningful name such as: FL - Invoice - After Update - Email reminder.

Explanations:

  • FL stands for “flow” to easily find the type of automation in the logs

  • Invoice to easily find the relevant object

  • After Update because we are after the update.

30. Enter a clear description for yourself. For example: Auto email reminder flow for invoices.

31. Save.

That's one thing done!

If you have new languages, levels, or reminder intensities, the flow will easily handle them. Each time an invoice is updated, the flow will only be taken into account if auto reminder has been checked. Otherwise, it will be completely ignored and will not impact your org's performance in any way.

Control field in the Administration tab

In order to specify under which condition the Apex Class MarkInvoiceForAutoReminder will check the Automatic dunning check box on the invoices concerned, we have to set up the condition in question 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 Automatic dunning condition as Control field for automatic emission of invoice reminders.


5. Click on the Confirm button.

Let's continue with the scheduling of the Apex job.

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: MarkInvoiceForAutoReminder

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.

To sum up: the Apex class MarkInvoiceForAutoReminder is checking all the invoices at the configured time if they meet the condition. If the Automatic dunning condition (Automation: Dunning - Fields) is true, the Apex class will check the box Automatic dunning on the invoice. This is the checkbox that triggers our process we just configured with process builder.

Now, let’s go over to testing!

Testing Approach

After the configuration, don’t forget to test your process.

Preparation

First make sure you can test on an invoice that meets the criteria for each scenario.

Tips for testing

  • Test your configuration in a Sandbox.

  • Replace contact email addresses with your email address in order to receive follow-up emails.

  • Create a list view of invoices with the filter Automatic dunning exception = False in order to follow the Next dunning date.

  • If Automatic dunning condition = True, the process can be manually started by checking the Automatic dunning checkbox. Wait (30 seconds to 1 minute) for the email to be sent and the fields to be updated.

  • Modify the Last dunning date in order to modify the date of the next reminder sent out and in order to get an invoice that meets the condition Automatic dunning condition = True.

  • For tests, the dunning process can be planned (step 2) several times a day. Plan the process for the next full hour, complete your dataset (invoices to be restarted). After the hour has passed, check the results.

If you want to run the Apex class directly, instead of scheduling the Apex job for testing, you can follow this procedure :

Procedure

  1. Open the Developer Console

  1. In the Debug menu > Open Execute Anonymous Window

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

// String CRON_EXP = ‘ss mm hh dd MM ? AAAA’;
String CRON_EXP = '00 00 10 04 03 ? 2020';
String lv_jobId = System.schedule(
   'MarkInvoiceForAutoReminder_Test'+Datetime.now(),
   CRON_EXP,
   new sofactoapp.MarkInvoiceForAutoReminder()
);

4. Put the date and hour in order to schedule the process in one minute.

  1. Click on Execute to run the script.