Closed perbrondum closed 2 years ago
line 5: Should read "fails when using USER struct, works when using SALESFORCERECORD"
@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?
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.
Indeed, adding id to the select list solves the problem.
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.
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.
Makes sense. Thanks for looking into this.
Per B Jakobsen CEO Tap2Sales.com @.***
On Mon, Nov 1, 2021 at 8:05 PM Michael Epstein @.***> wrote:
Closed #137 https://github.com/mike4aday/SwiftlySalesforce/issues/137.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mike4aday/SwiftlySalesforce/issues/137#event-5550897530, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALCYWDFYQCSDW7SMPAG6D2TUJ3QIDANCNFSM5CTIISFQ .
// 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.