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

'group by' count() soql fails in 9.0 #135

Closed
perbrondum opened this issue Aug 5, 2021 · 26 comments
Closed

'group by' count() soql fails in 9.0 #135

perbrondum opened this issue Aug 5, 2021 · 26 comments
Assignees
Labels

Comments

@perbrondum
Copy link

SELECT activitydate, status, Count(Id) Cnt
FROM task
WHERE isdeleted = false
GROUP BY activitydate, status

used to work, now it fails with :
Error: keyNotFound(CodingKeys(stringValue: "url", intValue: nil), Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "records", intValue: nil), _JSONKey(stringValue: "Index 0", intValue: 0), RecordCodingKey(stringValue: "attributes", intValue: nil)], debugDescription: "No value associated with key CodingKeys(stringValue: "url", intValue: nil) ("url").", underlyingError: nil))

@mike4aday mike4aday self-assigned this Aug 5, 2021
@mike4aday
Copy link
Owner

@perbrondum would you post your (formatted) code, please?

@perbrondum
Copy link
Author

private func groupedQuery() throws {
    let app = try ConnectedApp()
    let soql = """
        SELECT activitydate, status, Count(Id) Cnt
        FROM task
        WHERE isdeleted = false
        GROUP BY activitydate, status
    """
   // let soql = "SELECT activitydate, status, Count(Id) Cnt FROM task WHERE isdeleted = false GROUP BY activitydate, status"
    let pub: AnyPublisher<QueryResult<SObject>, Error> = app.query(soql: soql)
    pub.sink { completion in
        switch completion {
        case let .failure(error):
            print("Failed to execute grouped Query. Error: \(error)")
        case .finished:
            print("Success query")
            break
        }
    } receiveValue: { (tasks: QueryResult<SObject>) in
        for task in tasks.records {
            print(task.string(forField: "Cnt"))
        }
    }.store(in: &subscriptions)
}

@perbrondum
Copy link
Author

You get the error when you add the GROUP clause. The count is not really relevant.

@perbrondum
Copy link
Author

perbrondum commented Aug 10, 2021

Similar results from use of Max in select list (I assume it's using 'group by' internally).

SELECT max(id) MaxId
        FROM Account
        WHERE isdeleted = false

@mike4aday
Copy link
Owner

mike4aday commented Aug 10, 2021

Thanks @perbrondum - yes, any aggregating function in the query will cause the error. It's my fault - I re-introduced an error in ver. 9 that I had corrected in ver. 7. The current code expects the result to contain an array of records, each with an ID. But Salesforce returns a list of AggregateResult "records" when an aggregating function is used, and there is no ID. I'll fix it ASAP - trying to decide whether to fix with a breaking change (and update to ver 10) or a non-breaking change.

@perbrondum
Copy link
Author

perbrondum commented Aug 10, 2021 via email

@perbrondum
Copy link
Author

Is branch V9-fix-135 the fix for the bug?

@mike4aday
Copy link
Owner

@perbrondum it is -- but the fix isn't in there yet. I haven't had time yet to implement the fix. If you are blocked by the bug, I will accelerate the fix and try to get it done this week. I will notify you once ready. Thx

@perbrondum
Copy link
Author

perbrondum commented Aug 18, 2021 via email

mike4aday added a commit that referenced this issue Aug 22, 2021
@perbrondum
Copy link
Author

Thanks a lot for fixing this. Looks like I was able to pass all our tests with this fix.

@mike4aday
Copy link
Owner

mike4aday commented Aug 22, 2021

@perbrondum good to hear. I didn't have time to test yet - as soon as I have working unit tests (and figure out what's wrong per issue #137 that you opened) I will merge into main branch.

@perbrondum
Copy link
Author

Have you decided on a V9 or V10 release for the fix?

@mike4aday
Copy link
Owner

@perbrondum it'll be a minor release, updating version 9. I believe it's ready, but I wanted to do more testing before release. (For version 10, I'm considering a major release, in line with Apple's release of async/await in Swift 5.5.)

@perbrondum
Copy link
Author

perbrondum commented Nov 2, 2021 via email

@perbrondum
Copy link
Author

Mike - Are you still considering a 9 release for this fix or is it pushed to R10? Thanks.

@mike4aday
Copy link
Owner

@perbrondum - the fix will be in version 10. I'm working on v.10 now, writing tests and plan to release it soon.

@perbrondum
Copy link
Author

perbrondum commented Feb 16, 2022 via email

@mike4aday
Copy link
Owner

@perbrondum the major change in v10 will be async/await. I will try to reintroduce SOSL search in v10.0, but if I can't, I'll start working on that for v10.1 as soon as possible. Thanks

@perbrondum
Copy link
Author

perbrondum commented Feb 17, 2022 via email

@mike4aday
Copy link
Owner

mike4aday commented Feb 17, 2022

Thanks @perbrondum - it's good for me to know what's useful.

@mike4aday
Copy link
Owner

Fixed in version 10.0.0

@perbrondum
Copy link
Author

perbrondum commented Mar 29, 2022 via email

@mike4aday
Copy link
Owner

Thank you @perbrondum. I am loving async/await so far - so much simpler to follow, and requires much less code, as you noted. And thanks to the new Actor type, even multiple OAuth requests emanating simultaneously from different places in the code are easily 'bundled' into a single call. (The flip side is that I had to remove, for now at least, the ability to disable the automatic re-authentication -- i.e. no more "allowsLogin" switch in a request. So if you call a Salesforce method and in the unlikely event the refresh token flow fails, the user would be prompted to re-authenticate.)

@perbrondum
Copy link
Author

perbrondum commented Apr 14, 2022 via email

@mike4aday
Copy link
Owner

@perbrondum re. the issues you mentioned:

  1. Is TASK a custom object that you created to represent the Salesforce Task sObject?
  2. I'll be interested to know what you learn about this. I'm using Swiftly Salesforce with SwiftUI on a project, so haven't dealt with UIKit issues.
  3. I will fix that asap -- please see issue Is there another way to perform salesforce.nextResultPage in V10? #144 for a workaround in the meantime
    Thank you for the feedback.

@perbrondum
Copy link
Author

perbrondum commented Apr 15, 2022 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