You need to sign in to do that
Don't have an account?
Hanna Bergsma
Trigger Not Creating ContentDocumentLink
I have a (simple i thought???) trigger that creates a contentdocumentlink between an email attachment and the parent case of the email.
The CDL is not being created, thus the caseid is not a linkedentityid on that contentdocumentId. where am I going wrong?
Im thinking maybe this is actually trying to update/insert on a link that already exists and im not actually creating a new link??
The CDL is not being created, thus the caseid is not a linkedentityid on that contentdocumentId. where am I going wrong?
Im thinking maybe this is actually trying to update/insert on a link that already exists and im not actually creating a new link??
trigger relateEmailFileToParentCase on EmailMessage (after insert) { for (EmailMessage EM : Trigger.new){ if (EM.HasAttachment == TRUE ) { list<ContentDocumentLink> docLinks = [Select Id, ContentDocumentId from ContentDocumentLink where LinkedEntityId = :EM.id ]; List<ContentDocumentLink> listLinks = new List<ContentDocumentLink>(); Case parentCase = [SELECT Id from Case where Id=: EM.ParentId]; for(ContentDocumentLink docLink : doclinks){ docLink.Visibility = 'AllUsers'; docLink.LinkedEntityId = parentCase.id; docLink.ShareType = 'V'; docLink.ContentDocumentId = doclinks[0].ContentDocumentId; listLinks.add(docLink); } insert listLinks; } } }
Hanna Bergsma
Ive since made some edits but still no dice. it is not creating the new link to the case