Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keyNotFound "id" error on simple query #137

Closed
perbrondum opened this issue Aug 22, 2021 · 7 comments
Closed

keyNotFound "id" error on simple query #137

perbrondum opened this issue Aug 22, 2021 · 7 comments
Assignees
Labels

Comments

@perbrondum
Copy link

// Fails in 9.06 BETA with:

keyNotFound(CodingKeys(stringValue: "Id", intValue: nil), Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "records", intValue: nil), _JSONKey(stringValue: "Index 0", intValue: 0)], debugDescription: "No value associated with key CodingKeys(stringValue: "Id", intValue: nil) ("Id").", underlyingError: nil))

when using , works when using .

Not blocking for me, but seems related to the fix somehow.

private func getSFDCData() {
    DB.salesforce.identity().sink(receiveCompletion: { (completion) in
        switch completion {
        case .finished:
            break
        case let .failure(error) :
            print("Failed to login. Error: \(error)")
        }
    }) { identity in
        let userId = identity.userID
        
        let userSoql = "SELECT CompanyName FROM User where id = '\(userId)'"
        DB.salesforce.query(soql: userSoql).sink(receiveCompletion: { (completion) in
            switch completion {
            case let .failure(error):
                print("Failed to query(1) SFDC in MeetingVC. Error: \(error)")
            case .finished:
                break
            }
        }, receiveValue: { (userData : QueryResult<User>) in
            //
        }).store(in: &subscriptions)
    }.store(in: &subscriptions)
}
@perbrondum
Copy link
Author

line 5: Should read "fails when using USER struct, works when using SALESFORCERECORD"

@mike4aday
Copy link
Owner

mike4aday commented Oct 19, 2021

@perbrondum I believe the issue is that the Id field is not in the list of queried fields in your SOQL query; only CompanyName is queried. Does it work if you add Id to the queried field list?

@perbrondum
Copy link
Author

Sorry, just saw this. While id is not needed in the select list, I will check tomorrow if the bug still exists with it in.

@perbrondum
Copy link
Author

Indeed, adding id to the select list solves the problem.

@perbrondum
Copy link
Author

perbrondum commented Oct 22, 2021

Looked at this again, the id field does not have to be in the select list for this to work, but the Id field in the USER struct does have to be optional.
public var Id: String?
In my case I had the Id field as non-optional and that reproduces the error.

@mike4aday
Copy link
Owner

Hi @perbrondum - I assume User is a custom model struct you defined? If so, then any property defined as optional will work since the automatic decoding provided by Swiftly Salesforce via Swift's Decodable protocol will not throw an error if the server response is missing a value for that property. If the property is required, however, then it must be present in the JSON response, and the relevant field has to be in the SOQL select list.

@perbrondum
Copy link
Author

perbrondum commented Nov 1, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants