Step 5 - Schedule an Invoice
To initiate a scheduled invoice generation, an Autolaunched Flow invoking the Invoice API invocable class should be created where the flow will be called in a Batch Job.
How to create an Autolaunched Flow invoking the Invoice API
Follow the steps on how to create an Autolaunched Flow invoking the Invoice API invocable class:
Go to Setup.
In the Quick Find box, search and select Flows.
Click New Flow.
In the New Flow modal, select Autolaunched Flow (No Trigger).
Select a layout of your choice.
Add a new input variable that will serve as the placeholder for each record to process. This input variable is necessary for the Batch Job creation.
Click New Resource.
Complete the following steps in the New Resource modal, and click Done:
In the Resource Type, select Variable.
Provide your desired API Name.
In the Data Type, select Text.
Make sure that the Available for input (under the Availability Outside the Flow) is TRUE.
Add a Get Records element to retrieve the exact record where an invoice will be generated. For this example, we will be using Opportunity.
Drag/Add the Get Records element onto the canvas.
Complete the following steps in the New Get Records modal, and click Done:
Make sure to provide the exact object of the record.
Filter the records to be processed based on the stored record in the input variable
Add a Get Records element to retrieve the Gateway Account of the retrieved record from the previous action as it will be necessary to generate an invoice.
Drag/Add the Get Records element onto the canvas.
Complete the following steps in the New Get Records modal, and click Done:
Select Gateway Account as the Object.
Filter the records to retrieve ONLY the Gateway Account of the to-be-processed record.
Value = {!Get_Opportunity_Records.Gateway_Account__r.Id}
Add an Action element to invoke the Invoice API invocable class.
Complete the following steps in the New Action modal, and click Done:
Filter by Type and select Apex Action.
Find and select the Invoice API invocable class.
Provide the necessary details:
Amount (required) = The amount of the record
Currency (required) = The preferred currency to be used
Gateway Account Record (required) = The Gateway Account of the record
Related Record To (optional) = The record ID of the record you want to be linked in the Gateway Invoice. In this case, you can link the to-be-processed record to Gateway Invoice which will be created after the invoice generation.
Related Record To - Field (optional) = The custom lookup field under the Gateway Invoice object that will be populated with the record ID of the linked record.
Token (required) = The token that will be used in the payment processing during the invoice generation. You can use the Token from the Payment Source if your organization is using PosiPay’s Payment Source.
Token = {!Get_Opportunity_Records.Payment_Source__r.PosiPay__Token__c}
Save your Autolaunched Flow and make sure to activate it to be accessible in the Batch Job creation.
Create a Batch Job
Follow the steps on how to create a batch job
Go to Setup.
In the Quick Find box, search and select Batch Management.
Click New.
Enter some required data and click the autolaunch flow that’s been created a while ago and click Next. In next screen, select the recordId as Flow Input Variable and Opportunity as Object
Note: The required batch size would be 60 only to prevent hitting the governor limit
Click Save.
Create a Schedule Flow
Follow the steps on how to create a Scheduled-Triggered Flow
Go to Setup.
In the Quick Find box, search and select Flows.
Click New Flow.
In the New Flow modal, select Scheduled-Triggered Flow.
Set the date, time, and frequency.
Drag an action and find the batch name that you created a while ago in batch management and select it.
7. Click Save and activate.
Next place to go : Step 6 - Schedule a Gateway Settlement