function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Lynn TranLynn Tran 

Notes and Attachment Check Box Trigger

Hello!

I have Salesforce Enterprise. I have downloaded Eclipse SDK. 

I am looking to create a trigger for when a document is uploaded, it will trigger a check box in Contact (or another object if it's easier?) that a document uploaded. It would be even greater if it updated a text box with the date the document was created.

I have two documents, a 1) Policy form and a 2) Contract form. When a Policy form is uploaded via a form into Notes and Attatchments, I would like a box to EITHER check or have the date created appear. I would like to differentiate this form with the Contract form. Is this possible?

So

Policy form uploaded --> Date updated
OR
Policy form uploaded --> box checked

...Really whichever is easier to do!

Thanks so much.

Best,
Lynn
Best Answer chosen by Lynn Tran
PratikPratik (Salesforce Developers) 
Hi Lynn,

Here is  the sample code
Try this one:
https://help.salesforce.com/HTViewSolution?id=000181538&language=en_US

Thanks,
Pratik

All Answers

PratikPratik (Salesforce Developers) 
Hi Lynn,

As you have Force.com IDE setup, you can write the trigger on Notes & attachement on insert event.

Please refer to below Salesforce article:
https://developer.salesforce.com/forums/ForumsMain?id=906F00000008l9OIAQ

This will help you to get started,

Thanks & regards,
Pratik Munot

P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.
 
Lynn TranLynn Tran
Hi Pratik,

The article you sent me led me to another forum. I didn't find an answer there.

What I did do was:

1. Log into Force.com IDE
2. select "New" > "Apex Trigger"
3. Choose "Attatchment"
4. And chose my events as after insert, after update....

I found a script online but it didn't seem to work for me...Maybe I don't know where to go from here

This is what I ended up using..but I don't know if it's what I want it to do...

trigger TriggerForAttatchment on Attachment (after insert, after update) 
    {
         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;
                        }                        
}

 
PratikPratik (Salesforce Developers) 
Hi Lynn,

Here is  the sample code
Try this one:
https://help.salesforce.com/HTViewSolution?id=000181538&language=en_US

Thanks,
Pratik
This was selected as the best answer
PratikPratik (Salesforce Developers) 
Glad it helped!

Thanks,
Pratik
Ashley ShealeyAshley Shealey
How can you do this with Files instead of attachments?