Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Is it possible to make approval comments mandatory? There is one discussed here. http://christopheralunlewis.blogspot.in/2012/09/making-rejection-comments-mandatory-in.html

I've a two step approval process but I don't get comments in my trigger(pi.Steps[0].Comments).

Am I missing something here?

share|improve this question
1  
Can you post up some of your code? It might help us work out what the problem is –  Jon Hazan Sep 28 '12 at 10:17
    
It is the same as explained in the blog post except that I don't get the second step(first step is submission). I've written the trigger on an object(before update) - field update on approval. Will update the question with piece of code. –  Vignesh Sep 28 '12 at 16:12
    
Can you check if it works fine when you enter comments and reject the record. The problem I face is that the recent comments is not available when I query it inside the trigger. –  user651 Oct 1 '12 at 5:19
    
When i try to reject the record i got an error message. System.ListException: List index out of bounds: 0: Trigger.NPI_RequireRejectionComment: line 38, column 1". 38 if ((pi.Steps[0].Comments == null || pi.Steps[0].Comments.trim().length() == 0)) { –  user2259 Jan 22 '13 at 4:47

2 Answers 2

up vote 7 down vote accepted

Thanks for looking at my blog post.

From looking at your question, may I ask first, are you looking to make comments mandatory for approvals, rejections or both? In my example I only make comments mandatory on rejections. If you are looking to do this for approvals or both, then you would need to adjust the trigger code accordingly, including altering the SOQL query so it looks at approval messages for comments as well.

The fact that the approval process is a two step is not important, as the final rejection and approval methods fire the trigger. I just tested it out on a two step process and it worked as intended.

I hope that helps! If not please post your code with a bit more info and I will see how I can help.

Update 8/10/2012: I have an updated version of my mandatory comments technique that accounts for all steps in an approval steps in a process. I have written a blog post that explains how to do this.

share|improve this answer
    
Yes. As you said, trigger fires only on final step. I want to mandate comments for every step. Is it possible? –  Vignesh Oct 2 '12 at 17:10
    
Hello Vignesh, I've done a little bit more research into this, and I do believe it is possible using a twice executed trigger and a workflow rule. I'm in the process of confirming my theory. Watch this space I hope to be posting a new blog post containing the details within the next few days! –  Christopher Alun Lewis Oct 4 '12 at 16:56

I see the code working fine!!!

I tried to do the same from the demo and when I tried to reject a record i got the following error : Validation Errors While Saving Record(s) There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Operation Cancelled: Please provide a rejection reason!".

Some assumptions(could be silly) 1) Did you activate the approval process,if so check in the dev console to see if the entry criteria is evaluating to true. 2) You modified the trigger to point to the right custom object(some people do the workbook exercise in their dev org and the invoice object is on of the objects, just an assumption) 3) Did you do three workflow updates 1) approval update 2) pending update 3) rejection update?

These are some of the points I missed hopefully this is one of them you missed too. As for the code thanks for the link,another keep safe code :). works beautiful.

share|improve this answer
    
As christopher said, the trigger fires only on final approval/rejection. –  Vignesh Oct 2 '12 at 17:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.