You need to sign in to do that
Don't have an account?
Checkbox To Send New User Email
I've created a checkbox for the User page layout to send out a custom new user email. The goal is to send out the email when the checkbox is true, deploy the email, and then uncheck the box. I've got everything working in before update, but I cannot get it working for insert. I need to use After Insert to deploy the email because the email template I created in the apex class needs to be passed user field info (pass the User Id, name, email, etc). If I uncheck the box in the before insert, then the criteria to fire the after insert will no longer exist. I even tried making the method that unchecks the box @future, but that didn't work. I would prefer to create another component like a workflow that would fire after the triggers due to SFDC order of execution. Want a clean all apex solution for this.
This seems like a simple process, but I'm stuck at the moment. Any help would be greatly appreciated.
All Answers
Thanks sfdcfox! I overlooked the simplier approach. But I guess this means I couldn't do it in the trigger. I was equally curious to see if the limitation was my apex coding ability.
It's not that you can't use a trigger, is that the approach is a little more complicated than you'd expect:
This recursive trigger trick is necessary because you need to be able to update the user's checkbox ("before"), and you need a user ID ("after insert"). Using deepClone prevents the "DML on Trigger.new not allowed" error, and keeps the solution simple with no need for future methods or any other elaborate schemes.
When I responded I totally forgot why I had to use apex in the first place, it was the only way to auto-send an email to dynamic email recipients. I will use your suggestion of purposely setting off a recursive update to solve this issue. I will have to look more into what the deepClone is and does, but it sounds interesting. Thanks for the help.
For anyone else, who may be reading this thread. Here is the link I found on deepClone()
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_System_List_deepClone.htm
sfdcfox, that worked like a charm!
Final trigger code:
I want the PRM_NewUserEmail_Class.SendEmail(userList); PRM_NewUserEmail_Class.resetPRMcheckbox(userList); CLASSES.
I 'm bit confussed in passing them.
If you dont mind please share those two classes also.