• Himanshu Shekhar 76
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi All,

I have written a Trigger to update a custom field (Account__c) on ContentVersion.
The Trigger does not have any error but when I try to updload a file in an Account I got an error message "Can't updload (file name)".
Something wrong with the Trigger but I can't figure it why. 
trigger UpdateAccountonFile on ContentVersion (after insert) {

    Set<Id> docIds = new Set<Id>();
    
    for(ContentVersion cv : trigger.new){  
       
      if(cv.ContentDocumentId != null)
            {
                docIds.add(cv.ContentDocumentId);
        }  
    }     
  ContentDocumentLink c = [SELECT ContentDocument.Id, ContentDocument.Title, Id, LinkedEntityId FROM ContentDocumentLink WHERE ContentDocument.Id In:docIds ];   
    
   List<Account> accList = [SELECT Id, name FROM Account WHERE Id =:c.LinkedEntityId ];            
    
    for(ContentVersion cv : trigger.new){      
        
        if(accList.size() > 0){
            for(Account a : accList){
                cv.Account__c = a.Id;
            }
        }
        else{
            cv.Account__c = null; 
        }            
    }
}

Thanks in advance for your help.
Sylvie