You need to sign in to do that
Don't have an account?
DMLOptions in a before insert trigger
I'm going to try and write my order of actions and maybe then somebody can tell me that i'm missing something. What I am trying to accomplish is seperate web-to-lead's into 1 of three round robin assignment rules. The round robin rules function off of a custom object counter (1 for each rule)
-Form is filled out firing before insert trigger
-Trigger checks against a field entered from the form, logic is like this:
if x > 9, get the counter value for Large and save into custom lead field, set assignmentRuleID to rule1
if x > 3, get the counter value for Medium, save into custom lead field, set assignmentRuleID to rule2
else get the counter value for Small, save into custom lead field, set assignmentRuleID to rule3
Now the problem seems to be that the round robin assignment rules are based off of a formula field which is the MOD of the counter value stored in the lead. So if there are 5 people in my group and counter is 3 the mod value would be 2 meaning that the rule entry corresponding to that mod value would be called. But the leads are not being assigned at all. I'm thinking that since the rules are based off a formula value that maybe that value is not set because the lead has not really been saved yet.
I know the trigger is being called and that it is going through my logic but the rules are not being applied at all.I can also see that the lead gets the correct counter value and that its mod value is calculated correctly and stored in the lead.
Any help would be appreciated.
Alright so I got it working, not as cleanly as I would have liked but it works.
So I left my trigger as is except that i removed the DML set options code, all it does is verify the lead and depedning on the information in the lead assigns a routing number. Then I just made a long active assignment rule which combined the logic of all three assignments rules i was trying to assign in the code originnally.
This might pose problems when we start pushing data into SF from other sources but my assignment rule looks to custom fields that are not going to be used for anything else. So as long as I keep my active assignment rule ready for all senarios then i'm okay.
All Answers
Okay so i put the calculation of the mod number directly in the trigger and save it but the assignment rule is still not being called.
I should note that this is for Web-To-Leads.
This is my current code:
*************************************
This is the my debug log:
I wonder if the problem is there are 2 before insert triggers, and you are setting the DML options in the trigger that is running first. I don't know if it retains the options between triggers or not - perhaps you can write more into the debug log using system.debug() commands instead of putting data into lead fields. That way you can follow things along in the debug log as it goes.
I would recommend putting all your before insert logic into a single trigger anyways as you can't control which one happens first - maybe that will shed light on why the assignment rules aren't running as well.
That is a good thought. I'm not to sure how to "write more into the debug log", I'll take a look at the system.debug() references. I guess I will just try to expose the DML option in a few places.
I can definetly try combining my weblead before insert trigger and my leaddupcheck before insert trigger. Actually i can deleted my leaddupcheck all together. I'll try that right now.
I made my leaddupcheck trigger inactive as I wasnt using it anyways. I would delete it but frankly I have no idea how to delete it. This whole production/sandbox/IDE thing is a bit confusing.
In any case nothing changed except my debug log is shorter :)
Alright so I got it working, not as cleanly as I would have liked but it works.
So I left my trigger as is except that i removed the DML set options code, all it does is verify the lead and depedning on the information in the lead assigns a routing number. Then I just made a long active assignment rule which combined the logic of all three assignments rules i was trying to assign in the code originnally.
This might pose problems when we start pushing data into SF from other sources but my assignment rule looks to custom fields that are not going to be used for anything else. So as long as I keep my active assignment rule ready for all senarios then i'm okay.