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

Parent Child on Lookup Field Does not seem to return data #78

Open
gaberger opened this issue Dec 9, 2024 · 4 comments
Open

Parent Child on Lookup Field Does not seem to return data #78

gaberger opened this issue Dec 9, 2024 · 4 comments
Labels
question Further information is requested

Comments

@gaberger
Copy link

gaberger commented Dec 9, 2024

Not sure if this is a limitation of the library but if I try and use

SELECT Account.Technical_Solution_Engineer__r.FirstName FROM Opportunity

This reference Account.Technical_Solution_Engineer__r.FirstName, which is a lookup to the User table.

Returns nothing in the library response but execute in salesforce workbench

@k-capehart
Copy link
Owner

@gaberger Thank you for opening an issue!

I'll take a look at this when I can, but in the meantime, does this query work if you use the REST explorer in workbench? Or by using Postman? The endpoint should be something like /services/data/vXX.X/query?q=query

Also, double check that the user executing the auth flow has permissions for that field.

@gaberger
Copy link
Author

gaberger commented Dec 9, 2024

@k-capehart thanks for the quick response.
If I issue a request to

/services/data/v58.0/query?q=SELECT%20Account.Technical_Solution_Engineer__r.FirstName%20FROM%20Opportunity

I get back a list of records like

[Item 3]
   attributes
      Account
        attributes
           Technical_Solution_Engineer__r
               attributes
                  FirstName: Gary

@k-capehart
Copy link
Owner

@gaberger Thanks for checking.

This is how I wrote my code to access a field on a custom Lookup relationship. The key is to append "__r" in your golang struct field for a custom relationship. There might be opportunity to improve this (maybe with the go-soql package?).

type Contact struct {
  Id       string
  LastName string
}

type Account struct {
  Id                 string
  Primary_Contact__r Contact
}

type Opportunity struct {
  Id      string
  Account Account
}

opps := []Opportunity{}
err = sf.Query("SELECT Id, Account.Primary_Contact__r.LastName FROM Opportunity WHERE Account.Primary_Contact__c != null", &opps)
if err != nil {
  panic(err)
}
fmt.Println(opps)

Result in my test org:

➜  go-testing go run main 
[{006Dn00000EkTNFIA3 { { Stark}}}]

Let me know if that works, and if it doesn't, then please share some code snippets so I can further debug.

@k-capehart k-capehart added the question Further information is requested label Dec 9, 2024
@k-capehart
Copy link
Owner

@gaberger Were you able to resolve this?

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

No branches or pull requests

2 participants