{"record":{"id":"39852d0c9403663c","repo":"hcengineering/platform","slug":"lead-creation-failed","errorCode":null,"errorMessage":"Lead  creation failed","messagePattern":"Lead  creation failed","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugins/lead-resources/src/components/CreateLead.svelte","lineNumber":89,"sourceCode":"      state = rawStates[0]?._id\n      object.status = state\n    }\n  }\n\n  $: if (_space === undefined) {\n    if (funnels.find((it) => it._id === _space) === undefined) {\n      _space = funnels[0]?._id\n    }\n  }\n\n  $: funnel = funnels.find((it) => it._id === _space)\n\n  let kind: Ref<TaskType> | undefined = undefined\n\n  async function createLead () {\n    const sequence = await client.findOne(core.class.Sequence, { attachedTo: lead.class.Lead })\n    if (sequence === undefined || customer == null) {\n      throw new Error('Lead  creation failed')\n    }\n    if (kind === undefined) {\n      throw new Error('kind is not specified')\n    }\n\n    const incResult = await client.update(sequence, { $inc: { sequence: 1 } }, true)\n    const number = (incResult as any).object.sequence\n\n    const value: AttachedData<Lead> = {\n      status: state,\n      number,\n      identifier: `LEAD-${number}`,\n      title,\n      kind,\n      rank: '',\n      assignee: null,\n      startDate: null,\n      dueDate: null,","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/plugins/lead-resources/src/components/CreateLead.svelte#L71-L107","documentation":"Thrown in CreateLead.svelte when preconditions for creating a Lead fail: either the Sequence object for lead.class.Lead is missing (client.findOne returned undefined) or the customer contact is null/undefined. Sequences generate incrementing lead numbers, so without one the lead cannot be numbered, and a customer is required data.","triggerScenarios":"No core.class.Sequence document with attachedTo === lead.class.Lead exists in the workspace, or the component's `customer` variable was never set (null/undefined) when createLead() runs.","commonSituations":"Fresh workspace or migration where Lead sequence was never seeded; user submits the form before selecting a customer; component state reset losing the customer selection.","solutions":["Select a customer in the dialog before submitting","Ensure the Sequence object for Lead exists (seed it via plugin setup/upgrade routine, e.g. lead.class.Leed sequence with initial value)","Re-run product/workspace migrations so core sequences are created","Catch the error and surface which precondition failed (sequence vs customer)"],"exampleFix":"// before\nconst sequence = await client.findOne(core.class.Sequence, { attachedTo: lead.class.Lead })\nif (sequence === undefined || customer == null) {\n  throw new Error('Lead  creation failed')\n}\n// after\nconst sequence = await client.findOne(core.class.Sequence, { attachedTo: lead.class.Lead })\nif (sequence === undefined) {\n  await ensureSequence(lead.class.Lead, 0) // seed missing sequence\n}\nif (customer == null) {\n  ui.notify('Please select a customer first')\n  return\n}","handlingStrategy":"validation","validationCode":"const sequence = await client.findOne(core.class.Sequence, { attachedTo: lead.class.Lead })\nif (sequence === undefined) {\n  await ensureSequence(lead.class.Lead)\n}\nif (customer == null) {\n  throw new Error('Select a customer before creating a lead')\n}","typeGuard":"function canCreateLead (sequence: Sequence | undefined, customer: Ref<Contact> | null | undefined): boolean {\n  return sequence !== undefined && customer != null\n}","tryCatchPattern":"try {\n  await createLead()\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Lead')) {\n    ui.notify('Lead cannot be created: missing sequence or customer.')\n  } else throw err\n}","preventionTips":["Seed Sequence documents for every numbered class during workspace setup","Require customer selection in form validation before submit","Run migrations after plugin upgrades","Split compound precondition checks so the failure cause is clear"],"tags":["sequence-missing","validation","lead"],"backgroundTag":"sequence-object-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}