[SOLVED by removing trigger on ContentDocumentLink]

I am implementing uploading files as ContentDocument. For System Administrator all works good, but for non-registered site user it does not work. Creation of ContentVersion is good, but it fails at creation of ContentDocumentLink with exception INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY. Btw site user can successfully create all other objects (Opportunity, Account etc..)

I removed all dml except this one. I hardcoded Ids of existing ContentDocument and existing Opportunity. Owner of ContentDocument and Opportunity records is Site Guest User. And it fails only at creating ContentDocumentLink And Query for both Opportunity and ContentDocuments returns existing data. So User has access to both objects.

// ...       
       ContentDocumentLink link = new ContentDocumentLink(
           ContentDocumentId = 'xxxxxxxxxxx',
           ShareType = 'I',
           LinkedEntityId = 'xxxxxxxxxxxx'
       insert link;
// ...       
  • This may be a access permission issue. CRM Content Access is not available for Guest Users. Check this Idea link.
    – Saroj Bera
    Commented Feb 22, 2017 at 9:40
  • @SarojBera System administrator also has 'Salesforce CRM Content User' disabled, but all works Commented Feb 23, 2017 at 16:00
  • 1
    Hi @VladyslavKushney, it would help to see your sample code that reproduces the problem. The cross reference error usually means the running user either (A) doesn't have sharing access to the record or (B) the record being shared to doesn't exist. Double check the values for your lookup fields.
    – Doug Ayers
    Commented Feb 24, 2017 at 22:13
  • @DougAyers Please see edits Commented Feb 27, 2017 at 11:59

2 Answers 2


Try setting ShareType = 'V' instead of 'I'. The problem may be that Guest Users can only grant view access and not other share types. I've run into similar quirks myself with ShareType when developing Attachment to Files conversion code.

'V': Viewer premission. The user can explicitly view but not edit the shared file.


  • Unfortunately that did not help Commented Mar 7, 2017 at 13:41
  • Hey, try to add a trigger like my and see if it works for you. Commented Mar 9, 2017 at 17:58

It works if I remove trigger CDL on ContentDocumentLink (after insert) {...}

  • Hi, having same issue when i am going to create ContentDocumentLink with Guest User From portal it is not creating. Can you please give the solution what you have applied. Commented Oct 12, 2018 at 9:03
  • That's not very helpful if other code needs to have a ContentDocumentLink trigger. Do you mean you deleted the trigger or just disabled it? I hate when salesforce tries to make things better, but actually makes things worse. Commented Jun 12, 2019 at 19:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .