Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
trigger file on ContentVersion (after insert) { for(ContentVersion CV : trigger.new){ system.debug('New File Id is ' + CV.Id); } }
14:06:06:002 USER_DEBUG [3]|DEBUG|New File Id is 0686F00000CpoHCQAZ
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