<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CloudKit",
  "identifier" : "/documentation/CloudKit/CKContainer/fetchUserRecordID(completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "CloudKit"
    ],
    "preciseIdentifier" : "c:objc(cs)CKContainer(im)fetchUserRecordIDWithCompletionHandler:"
  },
  "title" : "fetchUserRecordID(completionHandler:)"
}
-->

# fetchUserRecordID(completionHandler:)

Fetches the user record ID of the current user.

```
func fetchUserRecordID(completionHandler: @escaping @Sendable (CKRecord.ID?, (any Error)?) -> Void)
```

## Parameters

`completionHandler`

The handler to execute with the fetch results.

## Discussion

The closure doesn’t return a value and takes the following parameters:

- The user record ID, or `nil` if the user disables iCloud or the device doesn’t have an iCloud account.
- An error if a problem occurs, or `nil` if CloudKit successfully retrieves the user record ID.

CloudKit returns a [`CKError.Code.notAuthenticated`](/documentation/CloudKit/CKError/Code/notAuthenticated) error when any of the following conditions are met:

- The device has an iCloud account but the user disables iCloud.
- The device has an iCloud account with restricted access.
- The device doesn’t have an iCloud account.

> Note: At startup, fetching the user record ID may take longer while CloudKit makes the initial iCloud account request. After the initial fetch, accessing the ID generally takes less time.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)