0

A button on an opportunity should bring all salesforce files from the related products. Trying to figure out the correct query for this

What i have found so far is the query for salesforce files:

SELECT ContentDocument.id 
FROM ContentDocumentLink 
WHERE LinkedEntityId = '{pv0}' 

And how to query products to opportunities:

How to query Products by Opportunity?

SELECT Id, Name, Account.Name, 
  (SELECT Quantity, UnitPrice, TotalPrice, 
   PricebookEntry.Name, PricebookEntry.Product2.Family FROM 
   OpportunityLineItems) 
FROM Opportunity WHERE Id = :YourOppId

My tuition is that i should combine these two somehow:

Something like:

SELECT ContentDocument.Id FROM ContentDocumentLink WHERE LinkedEntityId IN
(SELECT PricebookEntry.Product2Id FROM OpportunityLineItems WHERE Opportunity = ‘{pv0}’)

But I get an error that

The inner select field 'PricebookEntry.Product2Id' cannot have more than one level of relationships

Any ideas how i can solve this?

1

As the error states, you cannot specify related fields in the inner SELECT statement -- you can only specify fields that are in the object itself.

There is a Product2Id field in the OpportunityLineItem object (see documentation) so you should be able to use this field:

SELECT ContentDocument.Id FROM ContentDocumentLink WHERE LinkedEntityId IN
(SELECT Product2Id FROM OpportunityLineItem WHERE OpportunityId = '{pv0}')
  • Thanks I tried to add the query but I am still getting an error: ERROR at Row:1:Column:100 sObject type 'OpportunityLineItems' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. I tried without s on opportunitylineitems but still error: ERROR at Row:1:Column:126 No such column 'Opportunity' on entity 'OpportunityLineItem'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. What can I try next? – REMA Apr 2 at 12:25
  • Sorry I had a couple typos in that line, I've corrected them. FYI there is a document object reference here. – David Cheng Apr 2 at 14:18

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.