You need to sign in to do that
Don't have an account?
loveLearning
Trigger On attachment
I need to write some validatio/trigger on attachment object. Is there any possibility of doing that ?
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
I need to write some validatio/trigger on attachment object. Is there any possibility of doing that ?
To write a trigger on Attachment you have to use Eclipse. Open your Org in Eclipse then create a new trigger where you will get a picklist to select the Attachment Object. This is the only the way to write a trigger on Attachment. Below is the sample code of the trigger :
// Trigger to update the Attachment__c custom checkbox field in Custom Object(Custom_Obj__c) if it has any attachment.
trigger TiggerName on attachment (after insert)
{
List<Custom_Obj__c> co = [select id, Attachment__c from Custom_Obj__c where id =: Trigger.New[0].ParentId];
if(co.size()>0)
{
co[0].Attachment__c = true;
update co;
}
}
All Answers
To write a trigger on Attachment you have to use Eclipse. Open your Org in Eclipse then create a new trigger where you will get a picklist to select the Attachment Object. This is the only the way to write a trigger on Attachment. Below is the sample code of the trigger :
// Trigger to update the Attachment__c custom checkbox field in Custom Object(Custom_Obj__c) if it has any attachment.
trigger TiggerName on attachment (after insert)
{
List<Custom_Obj__c> co = [select id, Attachment__c from Custom_Obj__c where id =: Trigger.New[0].ParentId];
if(co.size()>0)
{
co[0].Attachment__c = true;
update co;
}
}
Hi Ngabrani,
Thanks for your trigger. How can I add an extra criterium to this trigger. I need to check if an attachment contains the name "RFP".
thanks
You could try something like --
trigger CheckAttachmentName on Attachment (before insert) {
for (Attachment att:Trigger.new) {
if(att.name.contains(''RFP) {
}
}
}
There is an example at the following link --
http://shivasoft.in/blog/salesforce/creating-trigger-on-attachment-in-salesforce/