1

How to retrieve AccountId on insert of file.

system.debug('LinkedEntityId $$$$'+LinkedEntityId)

always gives OwnerId.

But after insert of file, I can retrieve two rows from below query on ContentDocumentLink - one row with AccountId(LinkedEntityId) and one row with OwnerID(LinkedEntityId)

SELECT LinkedEntityId, Id, ContentDocumentId FROM ContentDocumentLink where ContentDocumentId ='069r00000002COX'

trigger UpdateAccountWithFileLink on ContentDocumentLink (after insert) {
        list<Id> accIdList = new list<Id>();
        for (ContentDocumentLink cdl : trigger.new) {
            system.debug('LinkedEntityId $$$$'+LinkedEntityId);
            if(String.valueOf(cdl.LinkedEntityId).startswith('001')){
              accIdList =  cdl.LinkedEntityId; 
            }
        }
    }
| improve this question | | | | |
  • if your event is INSERT of a file why don't you create a trigger on ContentDocument instead of ContentDocumentLink? – Andrei.Z Oct 6 '16 at 6:47
  • @Andrei.Z ParentID is not available on ContentDocument – sfdc Oct 6 '16 at 13:50
  • What's the problem here? Are you not getting the accountid is from linkedentityid? – Preya Oct 6 '16 at 13:56
  • am not getting accountid from linkedentityid.. But after insert of file, I can retrieve two rows from below query on ContentDocumentLink - one row with AccountId(LinkedEntityId) and one row with OwnerID(LinkedEntityId) – sfdc Oct 6 '16 at 14:02
  • SELECT LinkedEntityId, Id, ContentDocumentId FROM ContentDocumentLink where ContentDocumentId ='069r00000002COX' – sfdc Oct 6 '16 at 14:03
0

@Andrei.Z ParentId is available on ContentDocument if you enable CRM Content and assign to users.

| improve this answer | | | | |
  • 1
    Welcome to SF.SE Peter. For ContentDocument, the ParentId is the ID of the library that owns the document. It's created automatically when inserting a ContentVersion via the API for the first time. I don't think that's the same ParentId that he's looking for. Its best to provide a reference for your answers when posting on SF.SE. – crmprogdev Dec 10 '16 at 16:19

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.