{
  "id": "FLOW-009",
  "name": "Convert atomic flow: Lead-side BeforeSave Update cross-object lookup sees same-tx Opportunity (#2098)",
  "description": "Regression lock for issue #2098. Std_ConvertLead runs with runAtomically=true: Account/Contact/Opportunity are INSERTed in the parent atomic transaction, then stampConvertedAnchors UPDATEs the Lead with IsConverted=true + ConvertedOpportunityId=<newOpp>. That UPDATE fires the Lead-side RecordBeforeSave + Update flows. A child flow whose entry filter passes (IsConverted=true AND ConvertedOpportunityId IsNotNull) and whose body does a cross-object recordLookup against the just-created Opportunity must see that INSERT — read-your-own-writes within the same atomic outer tx. Pre-fix behavior (#1781 over-detached): the cross-object lookup ran on a fresh detached connection that could not see another tx's uncommitted writes, returned 0 rows, and the downstream assignment silently wrote nil onto the Lead's Description. Post-fix behavior: when isWithinAtomicFlowBoundary(ctx) is true, the lookup stays attached to the outer tx, the just-created Opportunity is visible, and the assignment lands the Opportunity's Name onto Lead.Description. Tenant-agnostic: standard SObject (Lead, Opportunity), standard fields (Description, ConvertedOpportunityId, IsConverted, Name). No __c business names, no PingCAP/TiDB identifiers.",
  "setup": [
    {
      "type": "http",
      "name": "Create synthetic BeforeSave Update flow on Lead via Tooling API",
      "method": "POST",
      "endpoint": "/services/data/v63.0/tooling/sobjects/Flow",
      "payload": {
        "MasterLabel": "FLOW-009 Lead BeforeSave Convert Stamp Opp Name",
        "ProcessType": "AutoLaunchedFlow",
        "Status": "Draft",
        "Metadata": {
          "apiVersion": "63.0",
          "label": "FLOW-009 Lead BeforeSave Convert Stamp Opp Name",
          "description": "Test-only BeforeSave Update flow that mirrors Lead_Convert_Filed_Set: cross-object recordLookup on the just-created Opportunity, then assignment of Opportunity.Name onto $Record.Description. Regression lock for issue #2098 (atomic-flow detach trade-off).",
          "status": "Draft",
          "processType": "AutoLaunchedFlow",
          "start": {
            "locationX": 50,
            "locationY": 0,
            "object": "Lead",
            "triggerType": "RecordBeforeSave",
            "recordTriggerType": "Update",
            "filterLogic": "and",
            "filters": [
              {
                "field": "IsConverted",
                "operator": "EqualTo",
                "value": { "booleanValue": true }
              },
              {
                "field": "ConvertedOpportunityId",
                "operator": "IsNull",
                "value": { "booleanValue": false }
              }
            ],
            "connector": { "targetReference": "getopportunity" }
          },
          "recordLookups": [
            {
              "name": "getopportunity",
              "label": "Get the freshly-created Opportunity",
              "locationX": 176,
              "locationY": 287,
              "object": "Opportunity",
              "filterLogic": "and",
              "filters": [
                {
                  "field": "Id",
                  "operator": "EqualTo",
                  "value": { "elementReference": "$Record.ConvertedOpportunityId" }
                }
              ],
              "getFirstRecordOnly": true,
              "storeOutputAutomatically": true,
              "connector": { "targetReference": "set_description_from_opp" }
            }
          ],
          "assignments": [
            {
              "name": "set_description_from_opp",
              "label": "Stamp Opportunity.Name onto Lead.Description",
              "locationX": 176,
              "locationY": 395,
              "assignmentItems": [
                {
                  "assignToReference": "$Record.Description",
                  "operator": "Assign",
                  "value": { "elementReference": "getopportunity.Name" }
                }
              ]
            }
          ]
        }
      },
      "expects": {
        "status_code": 201
      },
      "extract": {
        "flow009_version_id": "id"
      }
    },
    {
      "type": "http",
      "name": "Activate the new Flow version",
      "method": "POST",
      "endpoint": "/services/data/v63.0/tooling/sobjects/Flow/{flow009_version_id}/activate",
      "expects": {
        "status_code": 204
      }
    },
    {
      "type": "http",
      "name": "Create a fresh Lead to convert",
      "method": "POST",
      "endpoint": "/services/data/v63.0/sobjects/Lead",
      "payload": {
        "FirstName": "FLOW009",
        "LastName": "Convert-2098",
        "Company": "FLOW-009 Co",
        "Email": "flow009@example.com",
        "Description": "initial-pre-convert"
      },
      "expects": {
        "status_code": 201
      },
      "extract": {
        "lead_id": "id"
      }
    }
  ],
  "object": "LeadConvert",
  "method": "POST",
  "endpoint": "/services/data/v63.0/actions/standard/convertLead",
  "payload": {
    "inputs": [
      {
        "leadId": "{lead_id}",
        "convertedStatus": "Converted",
        "opportunityName": "FLOW2098-Opp-Name"
      }
    ]
  },
  "expects": {
    "status_code": 200
  },
  "extract": {
    "opportunity_id": "0.outputValues.opportunityId",
    "account_id": "0.outputValues.accountId",
    "contact_id": "0.outputValues.contactId"
  },
  "query_after": {
    "object": "Lead",
    "record_id": "{lead_id}",
    "retry": 5,
    "delay_ms": 500,
    "assertions": [
      {
        "field": "IsConverted",
        "operator": "eq",
        "value": true
      },
      {
        "field": "ConvertedOpportunityId",
        "operator": "is_not_null"
      },
      {
        "field": "Description",
        "operator": "eq",
        "value": "FLOW2098-Opp-Name"
      }
    ]
  },
  "teardown": [
    {
      "method": "DELETE",
      "endpoint": "/services/data/v63.0/sobjects/Opportunity/{opportunity_id}"
    },
    {
      "method": "DELETE",
      "endpoint": "/services/data/v63.0/sobjects/Contact/{contact_id}"
    },
    {
      "method": "DELETE",
      "endpoint": "/services/data/v63.0/sobjects/Account/{account_id}"
    },
    {
      "method": "DELETE",
      "endpoint": "/services/data/v63.0/sobjects/Lead/{lead_id}"
    },
    {
      "method": "DELETE",
      "endpoint": "/services/data/v63.0/tooling/sobjects/Flow/{flow009_version_id}"
    }
  ],
  "priority": "P1",
  "bug_ref": "#2098",
  "scene": "flow"
}
