twentyhq/twenty · error · CustomError
Failed to create record
Error message
Failed to create record
What it means
Thrown by useCreateOneRecord (useCreateOneRecord.ts:217-219) as a CustomError when the createOne GraphQL mutation response did not include the created record at the expected mutationResponseField. It is thrown AFTER a browser event has already been dispatched, indicating the mutation returned a malformed payload.
Source
Thrown at packages/twenty-front/src/modules/object-record/hooks/useCreateOneRecord.ts:213
? 'first'
: recordInput.position === 'last'
? 'last'
: null;
const createdRecord = createdObject.data?.[
mutationResponseField
] as ObjectRecordShared & BaseObjectRecord;
dispatchObjectRecordOperationBrowserEvent({
objectMetadataItem,
operation: {
type: 'create-one',
createdRecord: { ...createdRecord, position: positionToUse },
},
});
if (!isDefined(createdRecord)) {
throw new CustomError('Failed to create record');
}
return getRecordFromRecordNode({
recordNode: createdRecord,
});
};
return {
createOneRecord,
loading,
};
};
View on GitHub (pinned to 1f5dd2bbd2)
Solutions
- Refresh object metadata and retry the create.
- Inspect the mutation response in Apollo devtools to confirm the field name and shape.
- Verify the mutationResponseField used by the hook matches the current GraphQL schema.
- Check the server resolver logs for swallowed errors returning null data.
Defensive patterns
Strategy: try-catch
Type guard
const hasCreatedRecord = <T>(r: T | null | undefined): r is T => isDefined(r);
Try / catch
try {
await createOneRecord(input);
} catch (err) {
if (err instanceof CustomError && err.message === 'Failed to create record') {
// refetch metadata and let the user retry
}
} Prevention
- Keep object metadata in sync with the GraphQL schema.
- Refetch metadata before triggering create.
- Inspect mutation responses in Apollo devtools during development.
- Confirm the user has create permission before showing the form.
When it happens
Trigger: The create record mutation resolves but `createdRecord` (destructured from the response at mutationResponseField) is undefined/null. isDefined(createdRecord) is false.
Common situations: Object metadata and mutationResponseField out of sync (stale metadata); GraphQL schema change where the field name no longer matches; server returning partial data due to an error swallowed at the resolver; Apollo cache returning a partial/incomplete object.
Related errors
- Failed to merge records
- No getAuthTokensFromSSOExchangeToken result
- Field ${fieldMetadata.name} is missing, please refresh the p
- createCompany did not return an id
- createPerson did not return an id
AI-assisted analysis of twentyhq/twenty@1f5dd2bbd2 (2026-08-12).
Data as JSON: /api/errors/ebb8af806a941fd5.
Report an issue: GitHub.