You need to sign in to do that
Don't have an account?
Ashley Shealey
Checkbox Field when an attachment is added with specified keywords
I currently have a trigger that checks a box when an attachment is added to a custom object called "Contracts__c". I would like to expand this Trigger to only check the box if the actual attatched document includes certain keywords. Is this possible? Here is my current code:
trigger CountAttachment on Attachment (before insert, before delete)
{
if(trigger.isinsert){
List<Contracts__c> co = [select id from Contracts__c where id =: Trigger.New[0].ParentId];
If(co.size()>0)
{
co[0].Contract_Attached__c = True;
update co;
}
}
if(trigger.isdelete){
List<Contracts__c> co = [select id from Contracts__c where id =: Trigger.old[0].ParentId];
If(co.size()>0)
{
co[0].Contract_Attached__c = false;
update co;
}
}
}
trigger CountAttachment on Attachment (before insert, before delete)
{
if(trigger.isinsert){
List<Contracts__c> co = [select id from Contracts__c where id =: Trigger.New[0].ParentId];
If(co.size()>0)
{
co[0].Contract_Attached__c = True;
update co;
}
}
if(trigger.isdelete){
List<Contracts__c> co = [select id from Contracts__c where id =: Trigger.old[0].ParentId];
If(co.size()>0)
{
co[0].Contract_Attached__c = false;
update co;
}
}
}
I have checked your trigger code. it is not bulify. it will work only for single attachment. and also in this trigger you can't put filter for Keywords which you want. Please see below trigger code which will fulfill your requirement. don't forget to replace 'Your Key word' in this trigger.
Apex Trigger:
Let me know if you have any question on this. Please mark this "Solved" if it helps.
Thank You,
Hitesh Patel
Email :- hiteshpatel.aspl@gmail.com
http://mrjavascript.blogspot.in/
All Answers
I have checked your trigger code. it is not bulify. it will work only for single attachment. and also in this trigger you can't put filter for Keywords which you want. Please see below trigger code which will fulfill your requirement. don't forget to replace 'Your Key word' in this trigger.
Apex Trigger:
Let me know if you have any question on this. Please mark this "Solved" if it helps.
Thank You,
Hitesh Patel
Email :- hiteshpatel.aspl@gmail.com
http://mrjavascript.blogspot.in/
Functionality does works on Classic but not on the lightning page? any advice welcome.