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
Jonathan Wolff 7Jonathan Wolff 7 

Update field with old uploaded Ids by trigger

Hello, I have a trigger on ContentDocumentLink. When a file is uploaded the trigger populates a field. The problem is, that I need to reupload the Ids in every record now. Could you tell me an option so i can populate if with the latest Id in every record?
 
trigger ContentIdEintragen on ContentDocumentLink (after insert) {
    
    map<id,id> parentids = new map<id,id>();
    
    for(ContentDocumentLink cdl:trigger.new){
        parentids.put(cdl.LinkedEntityId,cdl.ContentDocumentId);
    }
    
    List<Mediathek__c> ContentDocumentIdupdate = new List<Mediathek__c>();
    
    for(Mediathek__c mt:[select id from Mediathek__c where id IN:parentids.keyset()]){
        
        if(parentids.containskey(mt.id)){
            mt.ContentDocumentID__c = parentids.get(mt.id);
            ContentDocumentIdupdate.add(mt);
        }
    }
    update ContentDocumentIdupdate;
}

 
AnkaiahAnkaiah (Salesforce Developers) 
Hi Jonathan,

If you have uploaded two files then both documents ids need to capture in parent record?

Thanks!!