SFDO-Community / declarative-lookup-rollup-summaries

Declarative Lookup Rollup Summaries (DLRS) is a community built and maintained Salesforce application that allows you to create cross object roll-ups declaratively - no code! For install instructions and documentation, visit our website https://sfdo-community-sprints.github.io/DLRS-Documentation/
https://sfdo-community-sprints.github.io/DLRS-Documentation/
BSD 3-Clause "New" or "Revised" License
691 stars 237 forks source link

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

Open matthewsouther opened 7 years ago

matthewsouther commented 7 years ago

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: dlrsContentDocumentLinkTrigger: 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

afawcett commented 7 years ago

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

tmiller910 commented 7 years ago

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 commented 6 years ago

I think this is fixed per pull request https://github.com/afawcett/declarative-lookup-rollup-summaries/pull/585

afawcett commented 6 years ago

Yes @DouglasCAyers i would agree.

afawcett commented 6 years ago

Fixed in v2.10

rishikumar2018 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Ok thanks for confirming, i'll re-open since our hope this was fixed via https://github.com/afawcett/declarative-lookup-rollup-summaries/pull/585 does not seem to have transpired sadly.

Ltowns commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Got it, thanks. Then it appears that by using ContentDocumentLink I can't filter by the Title or FileType. What I'm trying to do is identify if there is a File attached to an account that contains the title "Account Form" by getting a count using that as a filter.

On Tue, Feb 27, 2018 at 5:12 PM, Doug Ayers notifications@github.com wrote:

Hi @Ltowns https://github.com/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.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/afawcett/declarative-lookup-rollup-summaries/issues/433#issuecomment-369085447, or mute the thread https://github.com/notifications/unsubscribe-auth/AjMiNCdW48lhpUrLbP_R6lgcy6J7yPghks5tZKf3gaJpZM4K2rDv .

douglascayers commented 6 years ago

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

Jesus-GA commented 6 years ago

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 commented 6 years ago

@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 commented 5 years ago

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 commented 4 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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

JobbyC commented 2 years ago

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

SF-Q commented 2 years ago

@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 commented 2 years ago

@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 commented 6 months ago

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 commented 6 months ago

@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!