> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fusioncore.us/llms.txt
> Use this file to discover all available pages before exploring further.

# Configuring the Batch Job

> Schedule the SubscriptionRenewalBatch renewal job, tune its batch size, and understand what makes a Purchase Activity eligible for renewal.

## Overview

The nightly renewal job runs the `SubscriptionRenewalBatch` Apex class. It finds every eligible subscription, groups the work by customer, and generates renewal Orders for the next term. The job runs as `FC: Generate Renewal Orders` and uses the default schedule `0 0 3 * * ?` (3 AM every day) unless you set your own.

You schedule the job once. After that it runs on its own every night.

## Prerequisites

* You have the **System Administrator** profile, or a permission set that grants access to Setup and the ability to run anonymous Apex.
* The `SubscriptionRenewalBatch` class is deployed in your org (it ships with the Subscriptions package).

## How to Schedule the Renewal Batch Job

You can schedule the job from the Salesforce **Setup** menu without writing any code.

<Steps>
  <Step title="Open Setup">
    Click the gear icon at the top-right of Salesforce, then click **Setup**. The gear icon opens the administration menu.

    <Frame>
      <img src="https://mintcdn.com/fusionspan/dgaf-BkijdfqhSNr/images/end-user-guides/4857692206/Screenshot_2025-01-03_at_2.06.20-PM.png?fit=max&auto=format&n=dgaf-BkijdfqhSNr&q=85&s=c908574e2041038aacd56b64994d28f8" alt="The Salesforce gear icon with the Setup menu open" width="298" height="280" data-path="images/end-user-guides/4857692206/Screenshot_2025-01-03_at_2.06.20-PM.png" />
    </Frame>
  </Step>

  <Step title="Find Apex Classes">
    In the **Quick Find** search box, type `Apex Classes`, then click **Apex Classes**. Quick Find is the search box on the left side of the Setup page.

    <Frame>
      <img src="https://mintcdn.com/fusionspan/dgaf-BkijdfqhSNr/images/end-user-guides/4857692206/Screenshot_2025-01-03_at_2.07.34-PM.png?fit=max&auto=format&n=dgaf-BkijdfqhSNr&q=85&s=06894005e37eafeadf2265c429d230ec" alt="Quick Find filtered to Apex Classes in Setup" width="356" height="281" data-path="images/end-user-guides/4857692206/Screenshot_2025-01-03_at_2.07.34-PM.png" />
    </Frame>
  </Step>

  <Step title="Open Schedule Apex">
    On the Apex Classes list view, click **Schedule Apex**.

    <Frame>
      <img src="https://mintcdn.com/fusionspan/dgaf-BkijdfqhSNr/images/end-user-guides/4857692206/Screenshot_2025-01-03_at_2.09.53-PM.png?fit=max&auto=format&n=dgaf-BkijdfqhSNr&q=85&s=25eaabbfa15b02e20451380cb36f3833" alt="The Schedule Apex button on the Apex Classes page" width="935" height="308" data-path="images/end-user-guides/4857692206/Screenshot_2025-01-03_at_2.09.53-PM.png" />
    </Frame>
  </Step>

  <Step title="Fill in the schedule">
    Complete the scheduled job details:

    1. Give the job a name, for example `FC: Generate Renewal Orders`.
    2. For **Apex Class**, select `SubscriptionRenewalBatch`.
    3. Set the job to run **Weekly** on every day, or set the frequency your org needs.
    4. Set a **Start** and **End** date and a **Preferred Start Time** (3 AM matches the package default).

    <Frame>
      <img src="https://mintcdn.com/fusionspan/dgaf-BkijdfqhSNr/images/end-user-guides/4857692206/image-20241210-183913.png?fit=max&auto=format&n=dgaf-BkijdfqhSNr&q=85&s=53907a4a2b210245a16edc0edb00fdae" alt="The Schedule Apex form with job name, class, and timing filled in" width="2662" height="1754" data-path="images/end-user-guides/4857692206/image-20241210-183913.png" />
    </Frame>
  </Step>

  <Step title="Save">
    Click **Save**.
  </Step>

  <Step title="Verify the job was created">
    In **Quick Find**, type `Scheduled Jobs`, then click **Scheduled Jobs**. Your newly scheduled job appears in the list.

    <Frame>
      <img src="https://mintcdn.com/fusionspan/dgaf-BkijdfqhSNr/images/end-user-guides/4857692206/image-20241210-184802.png?fit=max&auto=format&n=dgaf-BkijdfqhSNr&q=85&s=0bbc1963b59fe2c95ebd9bb53351f012" alt="The renewal job listed on the Scheduled Jobs page" width="2662" height="1754" data-path="images/end-user-guides/4857692206/image-20241210-184802.png" />
    </Frame>
  </Step>
</Steps>

## How to Schedule the Job With Apex Code

If you want a custom run time, you can schedule the job from anonymous Apex instead. The class exposes two schedule methods.

<Steps>
  <Step title="Schedule with the default timing">
    Run `SubscriptionRenewalBatch.schedule();` with no argument to use the default 3 AM daily schedule.

    <Frame>
      <img src="https://mintcdn.com/fusionspan/dgaf-BkijdfqhSNr/images/end-user-guides/4857692206/Screenshot_2025-02-04_at_12.36.45-PM.png?fit=max&auto=format&n=dgaf-BkijdfqhSNr&q=85&s=6ce8dd736f463e146541a246be1e89ea" alt="Anonymous Apex calling SubscriptionRenewalBatch.schedule with no argument" width="1712" height="876" data-path="images/end-user-guides/4857692206/Screenshot_2025-02-04_at_12.36.45-PM.png" />
    </Frame>
  </Step>

  <Step title="Schedule with a custom cron expression">
    To choose your own run time, pass a cron expression to `SubscriptionRenewalBatch.schedule(String cron)`.

    <Frame>
      <img src="https://mintcdn.com/fusionspan/dgaf-BkijdfqhSNr/images/end-user-guides/4857692206/Screenshot_2025-02-04_at_12.37.18-PM.png?fit=max&auto=format&n=dgaf-BkijdfqhSNr&q=85&s=f14989affe23e809267af7b2284c7d58" alt="Anonymous Apex calling SubscriptionRenewalBatch.schedule with a cron expression" width="1734" height="898" data-path="images/end-user-guides/4857692206/Screenshot_2025-02-04_at_12.37.18-PM.png" />
    </Frame>

    The cron expression `0 0 1 * * ?` runs the job every day at 1 AM. A cron expression is the standard Salesforce way to describe a recurring schedule.
  </Step>
</Steps>

## Tuning the Batch Size

The job processes Purchase Activities in batches. You control how many records each batch handles with a Constant record named `FS_Subscription_Renewal_Batch_Job_Size` (`FCORE_BASE__Constant__mdt`). A **Constant** is a fusionCore configuration record that holds a single setting value.

If you do not create this Constant, the batch uses a default size of **200** records per batch. Lower the value if a renewal run hits Salesforce processing limits; raise it to process more records per batch.

## What Makes a Purchase Activity Eligible

The batch only selects Purchase Activities where the `Is_Ready_For_Renewal_Job__c` checkbox is true. That checkbox is a formula, so you cannot edit it directly. It evaluates to true only when **all** of these conditions are met:

* The subscription is not cancelled.
* `Renewal_Days__c` on the Subscription Plan is not blank.
* `Days_Until_Lapse__c` is not blank and is less than or equal to `Renewal_Days__c`.
* The product has `Is_Subscription__c` set to true.
* `FCORE_PAY__Status__c` is `Active` or `Expired`.
* `Renewal_Order__c` is blank (no renewal Order has been generated yet).
* The product is not flagged `Is_Not_Renewable__c`.
* `Renewal_Status__c` is `Pending`.

The `Renewal_Days__c` field on the Subscription Plan controls how many days before the expiration date renewals are generated. For example, set `Renewal_Days__c` to 30 to start generating renewal Orders 30 days before a subscription's `End_Date__c`.

<Info>
  **Important notes**

  * If `Is_Ready_For_Renewal_Job__c` is not true, the Purchase Activity is **not** picked up by the batch job.
  * The batch consolidates multiple Purchase Activities for the same customer into a single renewal Order. If you check `Skip_Consolidation__c` on a Purchase Activity, it is **processed separately** during renewal, even when other grouping conditions match.
</Info>

## Limitations and Common Pitfalls

* **The renewal engine guards against ineligible records.** If a Purchase Activity is fed to renewal with an existing renewal Order, the wrong status, `Renewal_Status__c` set to `Do Not Renew`, a status that is not `Pending`, a non-subscription product, or a product flagged `Is_Not_Renewable__c`, the renewal is rejected. Use the eligibility conditions above to predict what the batch will pick up.
* **Consolidation can merge subscriptions you expected to keep separate.** The batch groups multiple Purchase Activities per customer into one renewal Order unless they differ on customer, `End_Date__c`, `Renewal_Days__c`, `Auto_Charge__c`, or wallet item — or unless `Skip_Consolidation__c` is checked. Check `Skip_Consolidation__c` when you need a Purchase Activity renewed on its own Order.
* **A failing batch retries with a smaller batch size.** If a batch run fails, the job halves the batch size and retries, down to a size of 1, to isolate the problem record. A single bad record will not stop the rest of your renewals.
* **The job runs in system mode and without sharing.** The batch ignores record sharing rules and runs with full access, so it renews subscriptions regardless of who owns them.
* **A missing default Subscription Plan stops renewal.** If a product has no default Product Subscription Plan, renewal fails with `Default_Subscription_Plan_Is_Missing_V2`. Make sure each renewable product has exactly one default plan.
