You need to sign in to do that
Don't have an account?
RayAllen
Attachment to an Account changes a field in the Account upon attachment - How to?
Hi,
Our users will be attaching documents to accounts periodically. Upon attachment, I need a field ('review_needed' - a checkbox) to be changed to either checked or unchecked (doesn't matter, just needs to be modified).
How can I achieve this using a trigger? Is it possible to change the field using a workflow upon attachment (I'm guessing no).
Thanks in advance for any help you can provide!!!
Did you copied it correctly, It should not show any such compiler error.
Copy it, please tell me where are you creating this trigger, it should be in attachement.
All Answers
You can create a trigger for the Attachment object (I believe you'll have to do this via the Force.com IDE rather than the UI - though might have changed in the last release). This will have the id of the account that the attachment has been uploaded to in the ParentId field. Using this id, you can retrieve the account and apply the update.
Note that this would be invoked for all attachments, regardless of what sobject type they were attached to, so you may need to check the three character prefix of the id to check that it is indeed an account before retrieving and processing the parent.
I was hoping someone could give me an example of the code I would need to write. I'm very new to this and have really no idea where to start.
Thanks again.
You can use this code
I hope this will help you.
Hi,
this is the compile error I am receiveing: "Error: Compile Error: expecting right curly bracket, found 'EOF' at line 0 column -1"
Any ideas as to why?
Thank you so much for your help!
Did you copied it correctly, It should not show any such compiler error.
Copy it, please tell me where are you creating this trigger, it should be in attachement.
Hi Shashikant,
I was copying it into 'Customize>Accounts > Triggers'.
I'm guessing this is the wrong area? Where is 'Attachments'?
Please excuse my ignorance.
Thanks
You will need the Force.com IDE (Eclipse).http://wiki.developerforce.com/index.php/Force.com_IDE
There is one hack also for it, Go to any object's say Account's trigger list and click create new. Do not write any thing , In the URL, see the adderess bar you will see a entity query string parameter (e.g. entity=Account) and change it to Attachment (entity=Attachment) and press Enter. Newl loaded screen will accept Attachment trigger. Now copy my code in it.
If you face problem in implementing hack , i can help you in that. Please let me know if any issue in creating trigger.
That worked GREAT!
I can't thank you enough!!!
How do you deploy these changes to Live? There is no 'New' button for Triggers in the Live environment.
I would only like to deploy this change and no ther work I have done in my test environment.
For deployement you can either do by eclips or you can use change set.
You can see below links for more info
https://na10.salesforce.com/help/doc/en/changesets.htm
http://www.cloud-consulting.nl/en/Articles/Best-Practices/deployment-in-salesforcecom.html
https://na10.salesforce.com/help/doc/en/changesets_implementation_notes.htm
http://blog.sforce.com/sforce/2010/06/summer-10-is-almost-upon-us-but-i-have-been-recently-working-a-lot-with-a-feature-initially-introduced-in-spring-10-deployme.html
Awesome, great info.
I created a Change Set and included the Apex Trigger you created. Upon a test deployment in live, the validation failed:
UpdateAccReviewNeeded:Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required
Deploy ErrorAverage test coverage across all Apex Classes and Triggers is 0%, at least 75% test coverage is required.
You need to create a Test Method also
here is your test class
Please fill any required fields if there are any in account object. I hope above test class should work for you , let me know if any issues.
Hi,
where do I put this code and does it fit with the other code you wrote for me in this thread?
Thanks again...
Go to Develop -> Apex Classes -> Click New -> Copy Paste the code that I provided-> Click Save
You will see a class then , click on that class you will see a Run Button click on this , you will see your code coverage of trigger.
I received the following compiling error:
Error: Compile Error: expecting right square bracket, found '=' at line 13 column 58
Thanks again for all your help, I really appreciate it.
This query is slightly malformed:
it should be:
Note the additional 'where' keyword.
Thank you for taking the time to review this Bob! Worked great!!!