+ Start a Discussion
Nagesh Vattikonda5Nagesh Vattikonda5 

Opportunity Attachment Trigger help to set Attachment Attributes

I am trying to write a trigger to set an Opportunity Attachment attribute Private flag set to true, whenver an attachement is added/updated on opportuntiy record, I am new to trigger any help would be greatly appreciated.
thank you
Nagesh Vattikonda
Best Answer chosen by Nagesh Vattikonda5
Edwin VijayEdwin Vijay
Cool.. Please mark the appropriate answer as solved if that helped

All Answers

Edwin VijayEdwin Vijay
There are several options you could try out before deciding if you need a trigger.
  • Process builder
  • Flow
  • Workflow
In case these does not help here is an example of a trigger on the attachment object. 
https://help.salesforce.com/HTViewSolution?id=000181538 (http://​https://help.salesforce.com/HTViewSolution?id=000181538)
Nagesh Vattikonda5Nagesh Vattikonda5
thank you Vijay
btw how do i check if attachment is associated with an opportunity, I only want to update the Attachment attribute' Private' to True, if the attachment is assoicated with an opportunity
btw I tried other options without the success,before going with trigger
Edwin VijayEdwin Vijay
Your query will look like something below. Here is the link to the attachemtn object api https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_attachment.htm
Opportunity opp = [Select Id from Opportunity where name='test xyz'];
Attachment attrec = [Select Id,IsPrivate from attachment where ParentId=:opp.Id];
attrec.isPrivate = true;
update attrec;

This is only a sample, you would have to adapt this to use in a trigger
Nagesh Vattikonda5Nagesh Vattikonda5
Great thank you for your help, will check it out
Edwin VijayEdwin Vijay
Cool.. Please mark the appropriate answer as solved if that helped
This was selected as the best answer
Nagesh Vattikonda5Nagesh Vattikonda5
yes it dit, thank yu Edwin for your help