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

Can't aggregate Salesforce Files (ContentDocumentLink) as child object #433

Open
matthewsouther opened this issue Nov 18, 2016 · 26 comments

Comments

@matthewsouther
Copy link

Due to an apparent SOQL limitation with the ContentDocumentLink standard object, attempts to use DLRS to capture the ID of the most recent file on a parent record fail.

The validation error reads:

"Apex trigger dlrs_ContentDocumentLinkTrigger caused an unexpected exception, contact your administrator: dlrs_ContentDocumentLinkTrigger: execution of AfterInsert caused by: System.QueryException: Implementation restriction: ContentDocumentLink requires a filter by a single Id on ContentDocumentId or LinkedEntityId using the equals operator or multiple Id's using the IN operator.: Class.dlrs.LREngine.QueryExecutor.query: line 631, column 1"

See Success Community thread: https://success.salesforce.com/0D53A00002v7xXO
11-16-2016 10-50-18 am

@matthewsouther matthewsouther changed the title Can't aggregate Salesforce Files (ContentDocument) as child object Can't aggregate Salesforce Files (ContentDocumentLink) as child object Nov 18, 2016
@afawcett
Copy link
Collaborator

afawcett commented Dec 5, 2016

Thanks for sharing @matthewsouther, i'll flag this as a future enhancement, maybe there is a workaround the platform limitation.

@tmiller910
Copy link

Are there any updates to this thread? I'm trying to count the number of files for a custom object and run into this if I try to run via Process Builder or Real-Time. When I just run the lookup to calculate from the Manage screen, it runs through and updates.

@douglascayers
Copy link
Contributor

I think this is fixed per pull request #585

@afawcett
Copy link
Collaborator

afawcett commented Dec 7, 2017

Yes @douglascayers i would agree.

@afawcett
Copy link
Collaborator

afawcett commented Jan 1, 2018

Fixed in v2.10

@afawcett afawcett closed this as completed Jan 1, 2018
@rishikumar2018
Copy link

Hi,
We tried to implement this for attachments it is working fine when we are adding the attachment but when we delete the attachment it is not working as expected. We are trying to put the counts of attachments related to contract object. Count gets increased when we are adding the attachment but it is not decreased when we deleted the attachment.

Can you please help over it.

@SebasCanseco
Copy link

Hi @afawcett, I have tested this with v2.10 and I'm not getting reliable results:

  1. When I upload a file to a Contact once, the DLRS doesn't work, but when I immediately upload a second file it gets calculated but doesn't count the one of the files, so we are off the correct value by one.
  2. As @rishikumar2018 stated, I'm not able to get this to work when deleting a file from Contact. The Aggregate Result Field in the parent object (Contact) doesn't get updated.

Any clues? Thanks!

@afawcett
Copy link
Collaborator

afawcett commented Feb 4, 2018

Ok thanks for confirming, i'll re-open since our hope this was fixed via #585 does not seem to have transpired sadly.

@Ltowns
Copy link

Ltowns commented Feb 28, 2018

I'm unable to deploy the trigger for the child object ContentDocument, receive the following error: Error:
dlrs_ContentDocumentTest.testTrigger System.TypeException: DML operation INSERT not allowed on ContentDocument Class.dlrs.RollupService.testHandler: line 282, column 1 Class.dlrs_ContentDocumentTest.testTrigger: line 11, column 1. This is for a rollup counting ContentDocument on Account. Is this related to these reported issues with ContentDocumentLink?

@douglascayers
Copy link
Contributor

Hi @Ltowns,

You should use ContentDocumentLink object instead of ContentDocument or ContentVersion objects.

One reason is that sharing security is based on ContentDocumentLink object. Users, even admins, only can query and see ContentDocument or ContentVersion records explicitly shared to them. Any whose access is inferred by the user having access to the record the file has been shared to (e.g. account or contact) are ignored. So you would not get accurate counts and the counts would change based on the context user each time.

The other reason is that ContentDocument records can’t be inserted or updated directly which is why the auto-generated test fails. The document is created by Salesforce when a ContentVersion record is inserted and its ContentDocumentId field is null.

@Ltowns
Copy link

Ltowns commented Feb 28, 2018 via email

@douglascayers
Copy link
Contributor

You might try cross object filter criteria like “ContentDocument.Title = ‘Account Form’”

@Jesus-GA
Copy link

Jesus-GA commented Mar 5, 2018

Hello @afawcett,

Please, could you let us know if there is an estimated time of resolution for the issue reported by Sebas on the 31st of January?

Many thanks!
Jesus

@afawcett
Copy link
Collaborator

@Jesus-GA sadly i cannot give an ETA, this is an open source project and thus dependent on peoples personal time. It is flagged as a priorty issue though, which means when some time from a dev does come up this will be one of those looked at first.

@mkolodner
Copy link
Contributor

I'm also finding that the count in Realtime does not go down for linked Files (rollup based on ContentDocumentLink), though it goes up just fine. A Scheduled rollup does result in number going down for deleted files. But for some use cases a scheduled rollup may not meet the need.

@SebasCanseco
Copy link

Hi, I was wondering if this has been fixed. I'm working with another client and they could really use DLRS as long as it supports ContentDocumentLink object. Thanks for the hard work!

@jwallace2040
Copy link

Hi, I'm trying to count the number of files attached to a record. I'm getting this error, and I'm stuck tracking down the issue. Any help or guidance is appreciated.

dlrs_fistula2
dlrs_fistula1

@CathyJohnson-silverline

This issue where the count of files will correctly count for added files but not for deleted files is still occurring in the latest version (2.13). I noticed that if I select the option for "Remove from Record" then the decrementing on the count does work, but not for a Delete. We need this to be accurate in real time so, unfortunately, a scheduled run to correct any incorrect counts won't work.

I would love to understand why the behavior on this object is different from other Salesforce objects.

RelatedListForFilesOptions

@JobbyC
Copy link

JobbyC commented Oct 15, 2021

Hi, I have setup the roll-up based on ContentDocumentLink and created the trigger successfully. However, when I tested by upload a new file to the record, it throw me an error - "Can't add 1 file to Opportunity"

I read through the Salesforce Help & Training and it ask to inactive the ContentDocumentLink trigger (https://help.salesforce.com/s/articleView?id=000313353&type=1) . Please advice how or any althernative way I could create the roll-up to calculate the number of attachment / files on the object?

image

@aheber
Copy link
Contributor

aheber commented Oct 15, 2021

@JobbyC, are you able to collect any logging information for what is happening? Maybe use Salesforce Debug Logs and send us what you find there? Unfortunately that error message doesn't include any details.

Can you also include the details of your rollup so we can understand how you have it configured?

Completely random guess but I'd suggest one of two likely scenarios. Something in the rollup is configured incorrectly which is throwing an error or something about your opportunities is rejecting this record edit to save the rollup value, maybe a validation rule or something similar.

For future reference I'll do what I can here but I recommend you check into the Trailhead community group here, https://trailhead.salesforce.com/trailblazer-community/groups/0F9300000009O5pCAE. You're much more likely to get help and support there.

Thanks!

@SF-Q
Copy link

SF-Q commented Dec 28, 2021

Hi, Has the issue been fixed to reduce file count when a file is deleted? Are there any workarounds to address this?

@JobbyC
Copy link

JobbyC commented Dec 28, 2021

@SF-Q Yes managed to resolve it. I attached the roll-up that I did here, hope this help :)
image

@SF-Q
Copy link

SF-Q commented Dec 28, 2021

@JobbyC - I have the same configuration and the file count does not decrease when I delete files. Did you have to write additional code?

@JobbyC
Copy link

JobbyC commented Dec 28, 2021

@SF-Q If you use the delete option, it will not decrease the number. So, need to click the last option "Removed from Record" and the recalculation will work.
image

@riekusr
Copy link

riekusr commented Mar 15, 2024

I am trying to do this:

SELECT Id, ContentDocumentId,  ContentDocument.LatestPublishedVersion.Vervaldatum__c , ContentDocument.LatestPublishedVersion.Soort_Document__c   FROM ContentDocumentLink
WHERE LinkedEntityId  = '0010600002ET8ZbAAL'  AND ContentDocument.LatestPublishedVersion.Soort_Document__c = 'KvK document'
afbeelding

The query works, but how do i implement that in DLRS?

@aheber
Copy link
Contributor

aheber commented Mar 15, 2024

@riekusr I don't think this issue ticket would be the correct place to discuss your issue. Please reach out on the Trailblazer Community Group (https://trailhead.salesforce.com/trailblazer-community/groups/0F9300000009O5pCAE) and we can discuss it there.

Thanks!

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