
Linda begins configuring the Frisbii automations.
Since they use opportunities and offers, she wants to set up automatic invoicing from these two objects. She asks Vijay to explain the steps for this setup to her.
Trigger conditions on the opportunity object
The automatic generation of invoices from the opportunity object is based on four fields:
Automatic invoicing
Already invoices
Automatic invoicing condition
Automatic invoicing exception
Note: the formulas is 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.
Automatic invoicing | ||
Already invoiced | ||
Automatic invoicing condition
The formula is based on these fields:
Please adapt the condition due to your business needs. |
| |
Automatic invoicing exception
This formula is based on these fields
Please adapt the condition due to your business needs. |
Now that Linda understood the purpose of these fields, she can start the configuration.
Set 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 invoicing 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 invoicing refers to Automatic invoicing exception, and this one to Already invoiced, she has to sets up the fields in this order:
Check box Already invoiced
Formula field Automatic invoicing exception
Formula field Automatic invoicing condition
Lets start by setting up the field Already invoiced:
Check box
Object : Opportunity
Here you can see Linda's result:

Here you can find the procedure to set up the two formula fields:
Steps
1. Go to Setup > Object Manager > Opportunity
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 invoicing 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 opportunity 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 invoicing condition.
Note: In order to easily debug the process, if an opportunity 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 opportunity is an exception, he or she can modify the opportunity to meet the conditions or at least understands why the opportunity has not been processed.
Here you can see Linda's results:
After creating these fields, Vijay explains to Linda how to use them in the process builder.
Configuration of the control field
In order to inform the invocable method MarkOpportunityForAutoInvoicing under which conditions it should check the Automatic invoicing box (which will trigger the next process), you need to configure the control field in the Administration tab.
Steps
Go to the Administration tab of the Frisbii application.
Select the Automatic invoicing condition field that you created above as Control field for automatic creation of invoices from opportunitires.
Validate your choice

Creation of the flow
Vijay explains to Linda that he now uses only flows to automate processes in Salesforce, and no longer through the process builder.
Together, they set up two flows :
The first one on the opportunity object to create the invoice.
The second one on the invoice object which allows to update the opportunity after the creation of the invoice to indicate that the opportunity has already been invoiced
Let's start with the flow on opportunity.
Steps
Go to Set Up > Process Automation > Flow or type Flow in the quick search bar.
Choose Triggered Flow by a recording.
Double click on the symbol Start to set up the start.
3.1 Select the Opportunity object
3.2. Trigger the flow when: A record is updated.
3.3. Define as input conditions :
All conditions are met (AND)
sofactoapp_Auto_invoicing__c equal to True
Already_invoice__c equal to False
3.4. Run flow for updated records Only when a record is updated to meet the requirements of the conditions.
3.5. Optimize flows for : Actions and associated records.
3.6. Click on Finish.
4. Click on the More to add an item.
4.1. Click on Action and then search for Apex in the search bar.
4.2. Choose Opportunity_2_Invoice.
4.3.Give the action a name in the Label field and make sure the API name is written correctly.
4.4. Set the input values by putting {!$Record.Id} in Opportunityld field.
5. Save your flow.
That's a good thing done! Before moving on to testing, Linda and Vijay set up the second flow to update the opportunity.
Steps
1. Go to Setup > Process Automation > Flows or type Flows in the quick search bar..
2. Choose Flow triggered by a recording.
3. Double click on the Start symbol to Configure Startup.
3.1. Select the Invoice object.
3.2. Trigger the flow when: A record is created.
3.3. Define as input conditions :
Condition requirements: Formula Evaluates to True
AND
(NOT(ISBLANK({!$Record.sofactoapp__Offre__c})),
{!$Record.sofactoapp__Offre__r.sofactoapp__Auto_facturation__c} = true,
{!$Record.sofactoapp__Offre__r.Deja_facturee__c} = false)We will verify :
if an offer is linked to the invoice,
if the automation has been executed on this offer (the Auto billing box is checked)
Already invoiced is unchecked on the offer
3.4. Check the syntax by pressing the button.
3.5.Optimize the flows for : Actions and associated records.
3.6. Click on Finish.
4. Click the Plus to add an item.
4.1. Click Update Trigger Record.
4.2. Give a meaningful name.
4.3. How to search for records to update and set their value: Check Specify conditions to identify records, then set fields individually.
4.4. Update records of this object type: Opportunity
4.5. Filter the Opportunity records:
All conditions are met:
ID equal to {!$Record.sofactoapp__Opportunit__c}
4.6. Define the field values for Offer Records:
Alreadyinvoiced__c* <-- True
*Please note: Be sure to check how you named this field to put the correct API name on it.
4.7. Click on Done.
5. Save your flow.
6. Activate it.
That was fast! Let's go straight to planning the Apex class.
Schedule the Apex Job
If you want the invoice generation process to start at a certain time, you have to go through a scheduled Apex Class, here is the procedure of Salesforce for Scheduling Apex jobs.
Steps
1. From Setup, enter Apex Classes in the Quick Find box, select Apex Classes, then click Schedule Apex.
2. Select the class: MarkOpportunityForAutoInvoicing
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 task during the day, remember that Frisbii users can still work on the opportunities that already fall under the conditions. If the process wants to access an opportunity, 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 > EnviLa tâche planifiée est ensuite visible dans Configuration > 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 opportunity that meets the criteria, and therefore should be invoiced automatically.
For example in the case of Cloud Kicks:
the Opportunity Stage is won
the Automatic invoicing exception box is not checked (false)
and you have added the four fields in your page layout:
Automatic invoicing
Already invoiced
Automatic invoicing condition
Automatic invoicing exception
Steps
Open the Developer Console

In the Debug menu > Open Execute Anonymous Window
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 02 03 ? 2020';
String lv_jobId = System.schedule(
'MarkOpportunityForAutoInvoicing_Test'+Datetime.now(),
CRON_EXP,
new sofactoapp.MarkOpportunityForAutoInvoicing()
);4. Put the date and hour in order to schedule the process in one minute.

Click on Execute to run the script.
Was the test successful?
Automatic invoicing
Already invoices
Automatic invoicing condition
Automatic invoicing exception
The test was successful, if:
an invoice is linked to your opportunity
the check box Automatic invoicing is checked
the check box Already invoiced is checkedThis is not the case?
Please verify:
The formulas of the fields:
Automatic invoicing condition
Automatic invoicing exception
Is on your test opportunity:
The Automatic invoicing condition checked?
No? > Compare your opportunity with your set conditions
The checkbox Automatic invoicing exception is checked?
Yes? > Modify your test opportunity in order not to meet the exception criteria.
The configuration of your process :
Is the process activated?
If yes, please read again the procedure and verify your process.
You tested twice on the same opportunity and it is not working, even if you deleted the invoice?
Modify an option that makes the Automatic invoice condition check box unchecked, save, and then put the opportunity back in condition
Note: The process builder needs a modification of this kind, in order to be able to reprocess the record