https://sonarly.com/issue/18537?type=bug
The `useRelatedRecordCommands` hook throws an unhandled error when a relation field on an object (e.g., `people`) references a target custom object that no longer exists in the metadata store, crashing the page.
Fix: Two files changed to gracefully handle orphaned relation targets (relation fields that reference deleted/missing custom objects):
1. **`useRelatedRecordCommands.ts`** (line 60-64): Replaced `throw new Error(...)` with `continue`. When iterating ONE_TO_MANY relation fields to build command menu items, if the target object metadata is not found, the loop now skips that field instead of crashing the React render tree. This is the correct behavior — there's no command menu item to create for a non-existent object.
2. **`generateDepthRecordGqlFieldsFromFields.ts`** (line 57-61): Replaced `throw new Error(...)` with `return recordGqlFields` (the accumulator). Inside the `reduce`, when a relation field references a target object that doesn't exist in the metadata, we skip it and return the fields accumulated so far. This prevents the GraphQL field generation from crashing when building queries for objects with orphaned relations.
Both cases are data consistency edge cases — not programming invariants. When a custom object is deleted, relation fields on other objects may temporarily still reference it (due to localStorage cache staleness or incomplete server-side cleanup). Crashing the entire page is disproportionate; skipping the orphaned field is the correct degraded behavior.