0

I'm new to salesforce and soql and can't seem to figure out how to get the pandadocs for the opportunities. As far as I can tell the pandadocs have a related field called pandadoc__Opportunity__c but running this query doesn't work:

SELECT Account.BillingStreet, pandadoc__PandaDocDocument__c,
(
    SELECT Id, Contact.Name, Contact.Email, Contact.Phone, Role FROM OpportunityContactRoles
),
(
    SELECT Id, PricebookEntry.Id, Quantity, UnitPrice, TotalPrice, Platform_Specifics__c, PricebookEntry.Name, PricebookEntry.Product2.Family
    FROM OpportunityLineItems
)
FROM Opportunity WHERE AccountId = 'xxxxxxxx'

Any help would be much appreciated.

EDIT: The error is:

(url and query string here, just left out to for brevity)
resulted in a `400 Bad Request` response:
[{"message":"\nSELECT Account.BillingStreet, pandadoc__PandaDocDocument__c \n                        (truncated...)
(PHP stacktrace)

EDIT:

https://xxxxxxx.my.salesforce.com/services/data/v46.0/query/?q=SELECT%20Account.BillingStreet%2C%20pandadoc__PandaDocDocument__c%2C%0A%28%0A%20%20%20%20SELECT%20Id%2C%20Contact.Name%2C%20Contact.Email%2C%20Contact.Phone%2C%20Role%20FROM%20OpportunityContactRoles%0A%29%2C%0A%28%0A%20%20%20%20SELECT%20Id%2C%20PricebookEntry.Id%2C%20Quantity%2C%20UnitPrice%2C%20TotalPrice%2C%20Platform_Specifics__c%2C%20PricebookEntry.Name%2C%20PricebookEntry.Product2.Family%0A%20%20%20%20FROM%20OpportunityLineItems%0A%29%0AFROM%20Opportunity%20WHERE%20AccountId%20%3D%20%27xxxxxxxxxxxx%27
  • 1
    Can you update your post with the error message you are seeing? – Arnold Jr. Aug 20 at 17:18
  • Are you using the REST API? How are you authenticating, and are you able to complete other API calls? Have you tried the query using curl or PostMan? Since the error is 400 Bad Request, it would actually be helpful to have the URL & query string. – Thomas Taylor Aug 20 at 18:20
  • 1
    Yes i'm using REST. I'm authenticating via JWT. The query works if I take off the pandadoc__PandaDocDocument__c. I've added the url/query string to the question. – Chris Aug 20 at 18:24
  • 1
    Also, are you running this query this against a Salesforce Sandbox instance? – Thomas Taylor Aug 20 at 18:24
  • Yes but it should work in prod too. – Chris Aug 20 at 18:28
2

I took a quick look at the PandaDoc app in a dev org. There's no pandadoc__PandaDocDocument__c field on Opportunity. The pandadoc__PandaDocDocument__c object has lookups (many-to-one relationships) to Account, Contact and Opportunity. To get the records that are children of the Opportunity, you need to add another child query, eg:

SELECT Account.BillingStreet, 
(
    SELECT Id, Name, pandadoc__Status__c, pandadoc__UUID__c FROM pandadoc__Panda_Doc_Documents__r
)
(
    SELECT Id, Contact.Name, Contact.Email, Contact.Phone, Role FROM OpportunityContactRoles
),
(
    SELECT Id, PricebookEntry.Id, Quantity, UnitPrice, TotalPrice, Platform_Specifics__c, PricebookEntry.Name, PricebookEntry.Product2.Family
    FROM OpportunityLineItems
)
FROM Opportunity WHERE AccountId = 'xxxxxxxx'
  • 1
    Thanks @Thomas Taylor this is working!!1 <<--- shift happens. – Chris Aug 20 at 18:44
4

According to what you said - The query works if I take off the pandadoc__PandaDocDocument__c. This is because Panda documents are child objects of Opportunity. So, you need inner query to get documents:

SELECT Account.BillingStreet,
(SELECT Id, Name, pandadoc__Account__c, pandadoc__Contact__c, pandadoc__Lead__c 
    FROM pandadoc__Panda_Doc_Documents__r),
(SELECT Id, Contact.Name, Contact.Email, Contact.Phone, Role FROM OpportunityContactRoles),
(SELECT Id, PricebookEntry.Id, Quantity, UnitPrice, TotalPrice, Platform_Specifics__c, PricebookEntry.Name, PricebookEntry.Product2.Family
    FROM OpportunityLineItems
)
FROM Opportunity WHERE AccountId = 'aslf29alfjk8p23'

pandadoc is namespace.Panda_Doc_Documents is relationship name - you can find this in field definition of pandadoc__Opportunity__c in pandadoc__PandaDocDocument__c object.

  • Awesome, this lead me down the right path @Thomas Taylor answer is more correct as it works and doesn't throw any errors. – Chris Aug 20 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.