Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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.

Here are the necessary steps to follow:

...

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:

  1. Go to Setup.

  2. In the Quick Find box, search and select Flows.

  3. Click New Flow.

  4. In the New Flow modal, select Autolaunched Flow (No Trigger).

  5. Select a layout of your choice.

    Image Added
  6. Add a new input variable that will serve as the unique identifier placeholder for each record to process. This input variable is necessary for the Batch Job creation.

    1. Click the New Resource button.

    2. Provide Complete the following detailssteps in the New Resource modal, and click Done:

      Image Removed
      1. In the Resource Type = , select Variable.

      2. Provide your desired API Name = Desired API Name of the input variable

      3. Data Type = Text

      4. .

      5. In the Data Type, select Text.

      6. Make sure that the Available for input (under the Availability Outside the Flow) = is TRUE.

        Image Added
  7. Add a Get Records element to retrieve the exact record where an invoice will be generated.

    Image Removed

    . For this example, we will be using Opportunity.

    1. Drag/Add the Get Records element onto the canvas.

      Image Added
    2. Complete the following steps in the New Get Records modal, and click Done:

      1. Make sure to provide the exact object of the record.

      2. Filter the records to be processed based on the stored record in the input variable

      .
      1. Image Added

  8. 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.

    Image Removed
    1. Drag/Add the Get Records element onto the canvas.

      Image Added
    2. Complete the following steps in the New Get Records modal, and click Done:

      1. Select Gateway Account as the Object.

      2. Filter the records to retrieve ONLY the Gateway Account of the to-be-processed record.

        1. Value = {!Get_Opportunity_Records.Gateway_Account__r.Id}

          Image Added
  9. Add an Action element to invoke the Invoice API invocable class.

    Image Added
    1. Complete the following steps in the New Action modal, and click Done:

      1. Filter by Type and select Apex Action.

        Image Modified
      2. Find and select the Invoice API invocable class.

        Image Modified
      3. Provide the necessary details:

      Image Removed
        1. Amount (required) = The amount of the record

        2. Currency (required) = The preferred currency to be used

        3. Gateway Account Record (required) = The Gateway Account of the record

        4. 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.

        5. 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.

        6. 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.

...

          1. Token = {!Get_Opportunity_Records.Payment_Source__r.PosiPay__Token__c}

            Image Added
  1. 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

  1. Go to Setup.

  2. In the Quick Find box, search and select Batch Management.

  3. Click New.

  4. 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

...

  1. the governor limit

...

  1. Set up Flow

...

  1. Click Save.

Create a Schedule

...

Flow

...

  • Set Schedule

...

  • Select Object (ex. Opportunity)

Drag Get Records to the screen and select Gateway Account as Object and map the ID to the Opportunity Gateway Account

...

·        Drag Action to the Screen. Filter by Type and select Apex Action and select Invoice API as Action

·        Configure the apex action to pass the following Opportunity’s details to the invocable variables:

·   Gateway Account = Opportunity’s Gateway Account (custom field)

·   Amount = Opportunity’s Amount

·   Currency = Opportunity’s Currency

·   Token = Opportunity’s Payment Source (custom field) → Token

·   Relate Record To = Opportunity record ID

·  Relate Record To - Field = custom lookup field under the Gateway Invoice object that looks up to the Opportunity object

...

·        And Click Done

·   And after that, your flow should look like these

...

Follow the steps on how to create a Scheduled-Triggered Flow

  1. Go to Setup.

  2. In the Quick Find box, search and select Flows.

  3. Click New Flow.

  4. In the New Flow modal, select Scheduled-Triggered Flow.

...

  1. Set the date, time, and frequency.

...

  1. Drag an action and find the batch name that you created a while ago in batch management and select it.

    image-20240910-234320.pngImage Added

    image-20240910-234337.pngImage Added

    7. Click Save and activate.

Next place to go : Step 6 - Schedule a Gateway Settlement