You need to sign in to do that
Don't have an account?
Shannan Robillard 2
trigger to update a checkbox when certain files are uploaded
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
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
Thank you for shaing the code but it is not working if we deleted the file.
i tried your code in my case and everything works perfectly! Currenty i have problem with code coverage when iam deploying. Could i ask you for an example of your test class?
Thank you for you response
Mark