function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sascha DeinertSascha Deinert 

Problem with ContentDocument Trigger

I can't get the LinkedEntityId form ContentDocumentLink because the record is not created if the trigger fires. I tried to add Trigger.isAfter but the contentdocumentlink is still not created.
How can I solve it?
The goal is to check if the new uploaded document is related to sobject Mediathek__c.
trigger ContentDocumentMediathek on ContentDocument (after insert) {  
    if (Trigger.isAfter) {
        for (ContentDocument objCD : {        
            ContentDocument newCD = Trigger.newMap.get(objCD.Id);                            
            for (ContentDocumentLink cdl : [SELECT LinkedEntityId FROM ContentDocumentLink WHERE ContentDocumentId = :newCD.Id]) { 
                System.debug('cdl.LinkedEntityId: ' +cdl.LinkedEntityId);        
                If(cdl.LinkedEntityId.getSObjectType() == Mediathek__c.SObjectType) { system.debug('super');}


Sai PraveenSai Praveen (Salesforce Developers) 
Hi Sascha,

Can you try the trigger on ContentDocumentLink  object itself?