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

Is there another way to perform salesforce.nextResultPage in V10? #144

Closed
perbrondum opened this issue Apr 5, 2022 · 6 comments
Closed

Comments

@perbrondum
Copy link

No description provided.

@perbrondum perbrondum changed the title Is there another way to perform salesforce.nextRecordsPath in V10? Is there another way to perform salesforce.nextResultPage in V10? Apr 5, 2022
@mike4aday mike4aday self-assigned this Apr 14, 2022
@mike4aday
Copy link
Owner

@perbrondum sorry, I missed this issue. I neglected to include a 'convenience' method in Connection+API.swift but you could quickly create your own:

func nextResultsPage(path: String) async throws -> QueryResult<Record> {
    return try await request(service: Resource.Query.NextResultsPage(path: path))
}

I will add this to Connection+API.swift for next release.

@perbrondum
Copy link
Author

I tried to create the extension:

import Foundation
import SwiftlySalesforce

extension Connection {
    func nextResultsPage(path: String) async throws -> QueryResult<Record> {
        return try await request(service: Resource.Query.NextResultsPage(path: path))
    }
}

But I get: 'Query' is inaccessible due to 'internal' protection level

@mike4aday
Copy link
Owner

mike4aday commented Apr 14, 2022

Sorry @perbrondum - since Query is inaccessible, you could instead just create your own struct by copying Resource.Query.NextResults as:

struct MyOwnNextResultsPage<T: Decodable>: DataService {
            
    typealias Output = QueryResult<T>
            
    let path: String
            
    var batchSize: Int? = nil
            
    func createRequest(with credential: Credential) throws -> URLRequest {
        let headers = batchSize.map { ["Sforce-Query-Options" : "batchSize=\($0)"] }
        return try URLRequest(credential: credential, path: path, headers: headers)
    }
}

and then in your extension:

func nextResultsPage(path: String) async throws -> QueryResult<Record> {
    return try await request(service: MyOwnNextResultsPage(path: path))
}

(Or you could define the struct above within the extension method if the struct won't be reused elsewhere.)

@perbrondum
Copy link
Author

That works, thanks. Is there a reason that nextResultsPage returns <QueryResult and not a generic?

@mike4aday
Copy link
Owner

mike4aday commented May 1, 2022

Hi @perbrondum not sure I understand your question - the above nextResultsPage method returns a QueryResult<Record> but you could modify it to return QueryResult<T> instead where T is your own custom Decodable type, and Swiftly Salesforce would automatically decode the result's records, if any, into that type. I included my own type, Record, for those who don't want to define their own Decodable types and don't mind using strings to access the field values.

@perbrondum
Copy link
Author

I got the above to work with both Record and my own decodable type SFDCTask, by creating two versions of nextResultsPage. I tried but, my generics is not strong enough to be able to write a version of nextResultsPage that supports it. My only concern was if the official version of nextResultsPage will support generics? Btw, one of the reasons I continue to use my own type [SFDCTask] is that I'm not sure how to address items like 'task.Account.Name' using strings. Can you point me to a source (or example) for how to address this using strings?

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

No branches or pull requests

2 participants