nimajalali/go-force

When using QueryNext, where does the url parameter come from?

skirmish opened this issue · 5 comments

as an example;

var results *Account = new(Account)
err = fa.Query("SELECT Id, Name, BillingCity FROM Account LIMIT 10", &results)

Will retrieve one result.... How do I retrieve more than one row?

You need to setup a QueryResponse struct.

e.g.

type AccountQueryResponse struct {
     sobjects.BaseQuery

     Records []*Account `force:"records"`
}

accounts := &AccountQueryResponse{}
err = fa.Query("SELECT Id, Name, BillingCity FROM Account LIMIT 10", accounts)

Nice, thanks. Worked a treat. Good work.

moesy commented

What if we need more than the 2,000 rows limited ? I was under the impression the QueryNext function could be used to iterate over in batches of 2,000 by using the uri of the last output as the input until there are no records left. Anyone know the proper way to do this with this package?

@moesy Untested code ahead :)

type AccountQueryResponse struct {
     sobjects.BaseQuery

     Records []*Account `force:"records"`
}

accounts := &AccountQueryResponse{}
err = fa.Query("SELECT Id, Name, BillingCity FROM Account LIMIT 10", accounts)
if err != nil {
	//DO Something
}

if accounts.NextRecordsUri != "" {
	moreAccounts := &AccountQueryResponse{}
	err = fa.QueryNext(accounts.NextRecordsUri, moreAccounts)
	if err != nil {
		//DO Something
	}
}
moesy commented

Thank's for quick response @nimajalali testing it now but locked out of salesforce for a bit (API Overage). One part I'm not able to test yet but assume will be problematic is I probably can't append moreAcounts to Records given how AccountQueryResponse.Records is declared, ("[]*")would you recommend simply create an array within the method and work it through that way To build a comprehensive list?