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
KD sfdcKD sfdc 

I am new with Apex Trigger. Can someone help me on this?

I want to fetch (attachment) files id after inserting attachments under the Account record in lightning experince by using trigger.
sfdcMonkey.comsfdcMonkey.com
try following trigger on contentVersion (file) object :
trigger file on ContentVersion (after insert) {
    for(ContentVersion CV : trigger.new){
        system.debug('New File Id is ' + CV.Id);
        
    }
}
debug :
14:06:06:002 USER_DEBUG [3]|DEBUG|New File Id is 0686F00000CpoHCQAZ

Thanks, let us know if it helps you 
 
KD sfdcKD sfdc
Thanks Piyush , I want one more thing here. Can I save this contentversion Id in Text field DocumentId__c.
sfdcMonkey.comsfdcMonkey.com
DocumentId__c is filed in account object ? 
KD sfdcKD sfdc
Yes 
sfdcMonkey.comsfdcMonkey.com
right your trigger on ContentDocumentLink  object, try following code :
trigger ContentDocumentLinkTrigger on ContentDocumentLink (After insert) {
    String strObjPrefix;
    Set<Id> setCntDocIds = new set<Id>();
    set<Id> setOppIds = new set<Id>();
    
    map<id,ContentVersion> mapCV = new map<id,ContentVersion>();
    
    map<id,string> mapAccountWiseContentVersionId = new map<id,string>();
    for(ContentDocumentLink clIterator : Trigger.new) {
        strObjPrefix = String.valueOf(clIterator.LinkedEntityId).substring(0, 3);
        if(strObjPrefix == Account.sObjectType.getDescribe().getKeyPrefix()) {
            setCntDocIds.add(clIterator.ContentDocumentId);
            setOppIds.add(clIterator.LinkedEntityId);
        }
    }
    
    for(ContentVersion CV : [Select Id, ContentDocumentId From ContentVersion WHERE ContentDocumentId IN :setCntDocIds]){
        mapCV.put(CV.ContentDocumentId, CV);
    }
    
    for(ContentDocumentLink clIterator : Trigger.new) {
        mapAccountWiseContentVersionId.put(clIterator.LinkedEntityId, mapCV.get(clIterator.ContentDocumentId).Id);
    }
    
    list<Account> lstOppsToUpdate = new list<Account>();
    
    for(Account acc : [SELECT Id,DocumentId__c FROM Account where Id IN :setOppIds]) {
        acc.DocumentId__c = mapAccountWiseContentVersionId.get(acc.Id);
        lstOppsToUpdate.add(acc);
    }
    
    
    if(lstOppsToUpdate.size() > 0) {
        update lstOppsToUpdate;
    }
    
}
thanks let us know if it helps you