{
  "apiVersion": 63,
  "status": "Active",
  "label": "Standard Dated Conversion Rate Default Next Start",
  "description": "Guards and resolves a DatedConversionRate create before save. It rejects a duplicate (IsoCode, StartDate) pair with a custom error — one period per currency per start date is the Salesforce dated-rate rule, and the platform has no composite-unique constraint, so the guard lives here. It then derives NextStartDate from the next-later period for the same currency: that period's StartDate, or 9999-12-31 when none exists. NextStartDate is platform-derived (declared createable:false, so a supplied value is dropped before this flow runs), which means rows can arrive in any order — the derivation plus Std_DatedConversionRateCloseOnAppend's truncation converge on the same chain either way. Before-save with direct $Record assignment (the Std_OpportunityStageDerivedFields pattern); Std_DatedConversionRateCloseOnAppend closes the period the new row splits after the save commits.",
  "runAtomically": true,
  "start": {
    "locationX": 40,
    "locationY": 0,
    "object": "DatedConversionRate",
    "triggerType": "RecordBeforeSave",
    "recordTriggerType": "Create",
    "connector": {
      "targetReference": "GetDuplicatePeriod"
    }
  },
  "recordLookups": [
    {
      "name": "GetDuplicatePeriod",
      "label": "Get duplicate period for currency and start date",
      "locationX": 40,
      "locationY": 120,
      "object": "DatedConversionRate",
      "filterLogic": "and",
      "filters": [
        {
          "field": "IsoCode",
          "operator": "EqualTo",
          "value": {
            "elementReference": "$Record.IsoCode"
          }
        },
        {
          "field": "StartDate",
          "operator": "EqualTo",
          "value": {
            "elementReference": "$Record.StartDate"
          }
        }
      ],
      "getFirstRecordOnly": true,
      "storeOutputAutomatically": true,
      "assignNullValuesIfNoRecordsFound": true,
      "connector": {
        "targetReference": "DuplicatePeriodExists"
      }
    },
    {
      "name": "GetNextPeriod",
      "label": "Get next-later period for currency",
      "locationX": 40,
      "locationY": 360,
      "object": "DatedConversionRate",
      "filterLogic": "and",
      "filters": [
        {
          "field": "IsoCode",
          "operator": "EqualTo",
          "value": {
            "elementReference": "$Record.IsoCode"
          }
        },
        {
          "field": "StartDate",
          "operator": "GreaterThan",
          "value": {
            "elementReference": "$Record.StartDate"
          }
        }
      ],
      "sortField": "StartDate",
      "sortOrder": "Asc",
      "getFirstRecordOnly": true,
      "storeOutputAutomatically": true,
      "assignNullValuesIfNoRecordsFound": true,
      "connector": {
        "targetReference": "RouteNextStart"
      }
    }
  ],
  "decisions": [
    {
      "name": "DuplicatePeriodExists",
      "label": "Duplicate period exists?",
      "locationX": 40,
      "locationY": 240,
      "defaultConnector": {
        "targetReference": "GetNextPeriod"
      },
      "defaultConnectorLabel": "No duplicate",
      "rules": [
        {
          "name": "DuplicateFound",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "GetDuplicatePeriod.StartDate",
              "operator": "IsNull",
              "rightValue": {
                "booleanValue": false
              }
            }
          ],
          "connector": {
            "targetReference": "FailDuplicatePeriod"
          }
        }
      ]
    },
    {
      "name": "RouteNextStart",
      "label": "Route Next Start Date resolution",
      "locationX": 40,
      "locationY": 480,
      "rules": [
        {
          "name": "NoLaterPeriod",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "GetNextPeriod.StartDate",
              "operator": "IsNull",
              "rightValue": {
                "booleanValue": true
              }
            }
          ],
          "connector": {
            "targetReference": "AssignOpenEnded"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "AssignCapAtNextPeriod"
      },
      "defaultConnectorLabel": "Later period exists"
    }
  ],
  "customErrors": [
    {
      "name": "FailDuplicatePeriod",
      "label": "Duplicate dated rate period",
      "locationX": 200,
      "locationY": 240,
      "customErrorMessages": [
        {
          "errorMessage": "A dated exchange rate already exists for this currency and start date.",
          "statusCode": "DUPLICATE_VALUE"
        }
      ]
    }
  ],
  "assignments": [
    {
      "name": "AssignOpenEnded",
      "label": "Leave period open-ended",
      "locationX": 0,
      "locationY": 600,
      "assignmentItems": [
        {
          "assignToReference": "$Record.NextStartDate",
          "operator": "Assign",
          "value": {
            "dateValue": "9999-12-31"
          }
        }
      ]
    },
    {
      "name": "AssignCapAtNextPeriod",
      "label": "Cap period at next period start",
      "locationX": 80,
      "locationY": 600,
      "assignmentItems": [
        {
          "assignToReference": "$Record.NextStartDate",
          "operator": "Assign",
          "value": {
            "elementReference": "GetNextPeriod.StartDate"
          }
        }
      ]
    }
  ]
}
