{"record":{"id":"691f65bbe477f016","repo":"twentyhq/twenty","slug":"createcompany-did-not-return-an-id-691f65","errorCode":null,"errorMessage":"createCompany did not return an id","messagePattern":"createCompany did not return an id","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/twenty-apps/internal/twenty-partners/src/modules/shared/services/find-or-create-company-and-person.service.ts","lineNumber":29,"sourceCode":"): Promise<string | undefined> {\n  const name = companyName.trim();\n\n  const lookup = await findCompanyByName(client, name);\n\n  return lookup.companies?.edges?.[0]?.node?.id;\n}\n\nexport async function findOrCreateCompanyByName(\n  client: CoreApiClient,\n  companyName: string,\n): Promise<string> {\n  const existing = await findCompanyIdByExactName(client, companyName);\n  if (existing !== undefined) return existing;\n\n  const name = companyName.trim();\n  const result = await createCompany(client, name);\n  const id = result.createCompany?.id;\n  if (id === undefined) throw new Error('createCompany did not return an id');\n  return id;\n}\n\nexport async function findPersonIdByPrimaryEmail(\n  client: CoreApiClient,\n  email: string,\n): Promise<string | undefined> {\n  const primaryEmail = email.trim();\n\n  const lookup = await findPersonByEmail(client, primaryEmail);\n\n  return lookup.people?.edges?.[0]?.node?.id;\n}\n\nexport type FindOrCreatePersonByEmailInput = {\n  email: string;\n  firstName: string;\n  lastName: string;","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-apps/internal/twenty-partners/src/modules/shared/services/find-or-create-company-and-person.service.ts#L11-L47","documentation":"findOrCreateCompanyByName in the shared service guards createCompany(client, name) result. After a name-dedup lookup, it creates and asserts createCompany.id. An undefined id means the server returned a null/id-less company payload instead of throwing — the shared variant of the company guard used across modules.","triggerScenarios":"createCompany returns { createCompany: null } or no id. Causes: caller lacks Company create permission; name empty after trim; Company metadata out of sync; server-side validation; concurrent create beating the dedup lookup.","commonSituations":"Call site passing a whitespace-only companyName; role lacks Company create; manifest changed Company and metadata not re-synced; race creating the same company twice.","solutions":["Inspect the raw createCompany response for null payload or errors array.","Validate companyName.trim() is non-empty at the call site before invoking findOrCreateCompanyByName.","Confirm the caller's role has Company create permission and Company is synced.","Reproduce createCompany in the GraphQL playground to read the server rejection."],"exampleFix":"// before\nconst result = await createCompany(client, name);\nconst id = result.createCompany?.id;\nif (id === undefined) throw new Error('createCompany did not return an id');\n\n// after — guard input and surface result\nif (!companyName.trim()) throw new Error('companyName must be non-empty');\nconst result = await createCompany(client, companyName.trim());\nconst id = result.createCompany?.id;\nif (id === undefined) {\n  throw new Error(`createCompany did not return an id (result=${JSON.stringify(result)})`);\n}","handlingStrategy":"type-guard","validationCode":"import { isNonEmptyString } from 'twenty-shared';\n\nexport async function findOrCreateCompanyByNameSafe(client: CoreApiClient, companyName: string) {\n  if (!isNonEmptyString(companyName)) throw new Error('companyName must be non-empty');\n  return findOrCreateCompanyByName(client, companyName);\n}","typeGuard":"const hasCreatedCompanyId = (r: unknown): r is { createCompany: { id: string } } =>\n  typeof r === 'object' && r !== null &&\n  typeof (r as any).createCompany?.id === 'string';\n\nif (!hasCreatedCompanyId(result)) {\n  throw new Error(`createCompany returned no id: ${JSON.stringify(result)}`);\n}","tryCatchPattern":null,"preventionTips":["Validate companyName is non-empty before calling findOrCreateCompanyByName.","Always select and assert id on createCompany results.","Log the raw response when the id is missing.","Confirm Company create permission and metadata sync."],"tags":["graphql","sdk","mutation","partners","shared"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}