{"record":{"id":"a2fd7e14f654c67c","repo":"hcengineering/platform","slug":"contact-not-found","errorCode":null,"errorMessage":"contact not found","messagePattern":"contact not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugins/lead-resources/src/components/CreateLead.svelte","lineNumber":113,"sourceCode":"    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,\n      ...object\n    }\n\n    const customerInstance = await client.findOne(contact.class.Contact, { _id: customer })\n    if (customerInstance === undefined) {\n      throw new Error('contact not found')\n    }\n    if (!client.getHierarchy().hasMixin(customerInstance, lead.mixin.Customer)) {\n      await client.createMixin<Contact, Customer>(\n        customerInstance._id,\n        customerInstance._class,\n        customerInstance.space,\n        lead.mixin.Customer,\n        { customerDescription: null }\n      )\n    }\n\n    await client.addCollection(lead.class.Lead, _space, customer, lead.mixin.Customer, 'leads', value, leadId)\n    Analytics.handleEvent(LeadEvents.LeadCreated, { id: `LEAD-${number}`, customer })\n    dispatch('close')\n  }\n\n  const manager = createFocusManager()\n","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/plugins/lead-resources/src/components/CreateLead.svelte#L95-L131","documentation":"Thrown in CreateLead.svelte when the customer contact lookup fails: client.findOne(contact.class.Contact, {_id: customer}) returns undefined. The code needs the Contact instance to check/apply the lead.mixin.Customer mixin before finishing lead creation.","triggerScenarios":"The `customer` ref points to a contact that no longer exists, was deleted concurrently, or `customer` holds an invalid id; the contact exists in a different workspace than the client is connected to.","commonSituations":"Contact deleted by another user while the lead form is open; stale reference passed from a previous screen; account/workspace switch mid-flow.","solutions":["Re-select the customer contact in the dialog and retry","Verify the contact still exists (client.findOne) before opening the lead form","Refresh client data / reconnect to pick up deletions","Catch the error and ask the user to choose a different customer"],"exampleFix":"// before\nconst customerInstance = await client.findOne(contact.class.Contact, { _id: customer })\nif (customerInstance === undefined) {\n  throw new Error('contact not found')\n}\n// after\nif (customer !== undefined) {\n  const customerInstance = await client.findOne(contact.class.Contact, { _id: customer })\n  if (customerInstance === undefined) {\n    ui.notify('Selected customer was deleted. Please choose another contact.')\n    return\n  }\n}","handlingStrategy":"validation","validationCode":"if (customer === undefined) return\nconst contact = await client.findOne(contact.class.Contact, { _id: customer })\nif (contact === undefined) {\n  ui.notify('Customer contact not found; please reselect.')\n  return\n}","typeGuard":"function isContact (c: Contact | undefined): c is Contact {\n  return c !== undefined\n}","tryCatchPattern":"try {\n  await createLead()\n} catch (err) {\n  if (err instanceof Error && err.message === 'contact not found') {\n    ui.notify('The chosen customer was deleted. Select another contact.')\n  } else throw err\n}","preventionTips":["Verify the contact exists right before form submit","React to contact-deletion events to clear stale selections","Pass typed Ref<Contact> values, not raw strings","Avoid caching customer refs across sessions"],"tags":["reference-lookup","deleted-object","contact"],"backgroundTag":"referenced-object-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}