Hello Experts,
I need your support on below issue.
I have filed on opportunity, where the input should flow from a trigger which is written on contentdocument link. If an opportunity holds a document on it the filed has to be cheked-in else blank(default value).
We have a trigger which is not working... could someone can help on this..
--------------------------------------------------
trigger ContentDocsLinkStatusUpdate on ContentDocumentLink (after insert, after update) {
Set<Id> opportunityIdsToUpdate = new Set<Id>();
for (ContentDocumentLink cdl :Trigger.new){
if (cdl.LinkedEntityId.getSObjectType() == Opportunity.SObjectType){
opportunityIdsToUpdate.add(cdl.LinkedEntityId);
}
}
if (!opportunityIdsToUpdate.isEmpty()){
List<Opportunity> opportunitiesToUpdate = [
Select Id, Has_File__c,
(Select ContentDocumentId FROM ContentDocumentLinks WHERE LinkedEntityId = : opportunityIdsToUpdate)
FROM Opportunity WHERE Id IN : opportunityIdsToUpdate];
for (opportunity opp : opportunitiesToUpdate){
for(Opportunity ID :trigger.new){
If(opp.Id !=null){
Id.Has_Attachment__c = True;
}
else{
Id.Has_Attachment__c = false;
}
}
update opportunitiesToUpdate;
}
}
}
----------------------------------------------------------------------------------------
#Salesforce Developers #Salesfoce Developer