• Rishi Kumar 135
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
New to Apex coding so I am hoping that the community can help me. I am trying to create a trigger from Files that will check a custom checkbox field on the Opportunity when two Executed documents are uploaded to the related "Files" list. Here is what I have so far: 

trigger ContentDocumentLinkTrigger on ContentDocumentLink (before insert, before delete)
{
if(trigger.isinsert){
List<Opportunity> co = [select id from Opportunity where id =: Trigger.New[0].Id];
If(co.size()>0)        
{            
co[0].Executed_Docs_Attached__c = True;            
update co;        
}
}


if(trigger.isdelete){

List<Opportunity> co = [select id from Opportunity where id =: Trigger.old[0].Id];        
If(co.size()>0)        
{            
co[0].Executed_Docs_Attached__c = false;            
update co;        
}
}
}
However, this code is not updating the checkbox and I am not sure how or if I can specify to only update the checkbox if the file name has "Executed" included. Any thoughts would helpful. 
Thanks
Hi everyone,

Here is my business requirement:

On the standard Quote object, I have a custom checkbox field called PO_Attached__c. If a File is uploaded to a Quote record, PO_Attached__c should be updated to true. I currently achieve this functionality using the Attachments functionality by use of an Apex trigger.

However, we are now migrating to Files. I have updated my code block as below. It saves fine, but the checkbox is never updated. Any ideas why? Thanks in advance.
 
trigger quoteAttachment2 on ContentDocumentLink (after insert) {

                        List<Quote> listOfQuote = [select id from Quote where id =: Trigger.New[0].LinkedEntityId];
                        if(listOfQuote.size()>0)
                        {
                                    listOfQuote[0].PO_Attached__c = true;
                                    update listOfQuote;
                        }                                                                   
            }