{
  "id": "R-2126",
  "name": "Quote create with null Account.BillingCountryCode returns 400 FIELD_INTEGRITY_EXCEPTION, not 500",
  "description": "Regression for issue #2126: when Account.BillingCountryCode is NULL and the Quote.Name autonumber format references {Account.BillingCountryCode}, creating a Quote without a Name must return 400 FIELD_INTEGRITY_EXCEPTION (user-recoverable) instead of 500 InternalServerError. Requires tenant overlay with the Quote.Name autonumber format active.",
  "object": "Quote",
  "method": "POST",
  "endpoint": "/services/data/v63.0/sobjects/Quote",
  "setup": [
    {
      "type": "sql",
      "name": "Create Account for R-2126 WITHOUT BillingCountryCode to trigger autonumber token resolve failure",
      "sql": "INSERT INTO Account (Id, Name, IsDeleted, SystemModstamp) VALUES (%s, %s, %s, %s)",
      "params": [
        "r2126-acc-01",
        "R-2126 Account NullBCC",
        0,
        "{db_timestamp}"
      ]
    },
    {
      "type": "sql",
      "name": "Create Opportunity for R-2126 linked to the null-BCC Account",
      "sql": "INSERT INTO Opportunity (Id, Name, AccountId, StageName, CloseDate, Amount, IsDeleted, SystemModstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
      "params": [
        "r2126-opp-01",
        "R-2126 Opportunity",
        "r2126-acc-01",
        "Prospecting",
        "2026-12-31",
        50000,
        0,
        "{db_timestamp}"
      ]
    }
  ],
  "payload": {
    "OpportunityId": "r2126-opp-01",
    "Status": "Draft"
  },
  "expects": {
    "status_code": 400,
    "body_contains": {
      "0.errorCode": "FIELD_INTEGRITY_EXCEPTION"
    }
  },
  "response_assertions": [
    {
      "field": "0.message",
      "operator": "contains",
      "value": "Account.BillingCountryCode"
    },
    {
      "field": "0.message",
      "operator": "not_contains",
      "value": "AssignOne"
    },
    {
      "field": "0.message",
      "operator": "not_contains",
      "value": "token resolve failed"
    },
    {
      "field": "0.message",
      "operator": "not_contains",
      "value": "no chain resolved"
    }
  ],
  "teardown": [
    {
      "type": "sql",
      "sql": "DELETE FROM Opportunity WHERE Id = %s",
      "params": [
        "r2126-opp-01"
      ]
    },
    {
      "type": "sql",
      "sql": "DELETE FROM Account WHERE Id = %s",
      "params": [
        "r2126-acc-01"
      ]
    }
  ],
  "priority": "P0",
  "bug_ref": "#2126",
  "scene": "quote"
}
