user1092808
user1092808

Reputation: 393

Querying on recordID results in "Internal server error"

When I execute this code:

CKDatabase *publicDatabase = [[CKContainer defaultContainer] publicCloudDatabase];
CKRecordID  *recordID  = [[CKRecordID alloc] initWithRecordName: @"95263874-C860-4190-A2BB-08B3E652B7AA"];
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"%K == %@", @"recordID", [[CKReference alloc] initWithRecordID: recordID action: CKReferenceActionNone]];
CKQuery     *query     = [[CKQuery alloc] initWithRecordType: @"Case" predicate: predicate];
[publicDatabase performQuery: query inZoneWithID: nil completionHandler: ^(NSArray *results, NSError *error) {
     if (error) {
        NSLog(@"Error = %@", error);
    } else {
        NSLog(@"Success");
    }
}];

I get this error:

<CKError 0x618000042670: "Server Rejected Request" (15/2000); server message = "Internal server error"; uuid = 122AB9AA-6949-442D-B9D7-736A5B7D2EE5; container ID = "iCloud.net.xxxxxxx">

However, if I change the predicate to this:

NSPredicate *predicate = [NSPredicate predicateWithFormat: @"PatientName = %@ ", @"Doe, John"];

The retrieve works correctly. I have verified that John Doe has record name that I am searching for. I have also tried toggling the iCloud "Capability" in the project settings. I have spent hours and hours on this issue and have tried many variations. Nothing works!

Upvotes: 0

Views: 404

Answers (1)

farktronix
farktronix

Reputation: 3950

Make sure that you've marked Record ID as queryable for this record type in the CloudKit Dashboard.

Select your record type and click on "Metadata Indexes". Check the Query checkbox next to the Record ID field and this error should go away.

Aside from that, rmaddy's answer is right- if you're just trying to fetch a record by its identifier you should use CKFetchRecordsOperation instead of a query.

Upvotes: 1

Related Questions