You need to sign in to do that
Don't have an account?
tmbarry
Trigger Doing funny things.
I created a simple trigger to increment a numeric value on an object if a certain task is created.
trigger UpdateSentMail_01 on Task (after insert){ // Tasks that meet criteria, and new tasks to create Task[] qualifiedTasks = new Task[0], newTasks = new Task[0]; // Map of SD Members Map<Id,SD_Member__c> members = new Map<Id,SD_Member__c>(); // Find qualifying tasks for(Task record:Trigger.new) if(Record.subject!=null && record.subject.contains('Print Sf Order Submitted') && record.status == 'Completed') qualifiedtasks.add(record); // Obtain member ID values for(Task record:qualifiedtasks) members.put(record.whatid,null); // If there are any membes to query, do so. if(!members.isempty()) members.putall([select id, letter_counter__c from SD_Member__c where id in :members.keyset()]); double i = 0; for(Task record:qualifiedtasks) { // Get the current Letter Counter value i = members.get(record.whatid).letter_counter__c; // Increase the Letter Counter by 1 i=i+1; members.get(record.whatid).Send_Monthly_Letter__c=False; } update members.values(); for(Task record:qualifiedtasks) { members.get(record.whatid).Send_Monthly_Letter__c=True; members.get(record.whatid).Make_1st_Follow_Up_Call__c=False; members.get(record.whatid).Make_2nd_Follow_Up_Call__c=False; members.get(record.whatid).Make_3rd_Follow_Up_Call__c=False; members.get(record.whatid).Letter_Counter__c=i; } update members.values(); }
Before I entered the test tasks using excel connector here is what my test data looked like:
Record ID | First Name | Last Name | Letter Counter |
a02W000000A8SgfIAF | Test | Record_0115 | 17 |
a02W000000A8SggIAF | Test | Record_0155 | 1 |
a02W000000A8SghIAF | Test | Record_0135 | 8 |
a02W000000A8SgiIAF | Test | Record_0175 | 21 |
a02W000000A8SgjIAF | Test | Record_0195 | 14 |
a02W000000A8SglIAF | Test | Record_0116 | 16 |
a02W000000A8SgmIAF | Test | Record_0156 | 0 |
a02W000000A8SgnIAF | Test | Record_0136 | 9 |
a02W000000A8SgoIAF | Test | Record_0176 | 22 |
a02W000000A8SgpIAF | Test | Record_0196 | 15 |
a02W000000A8SgqIAF | Test | Record_0117 | 17 |
a02W000000A8SgrIAF | Test | Record_0157 | 0 |
a02W000000A8SgsIAF | Test | Record_0137 | 10 |
a02W000000A8SgtIAF | Test | Record_0177 | 23 |
a02W000000A8SguIAF | Test | Record_0197 | 16 |
a02W000000A8Sh0IAF | Test | Record_0118 | 18 |
a02W000000A8Sh1IAF | Test | Record_0158 | 0 |
a02W000000A8Sh2IAF | Test | Record_0138 | 11 |
a02W000000A8Sh3IAF | Test | Record_0178 | 24 |
a02W000000A8Sh4IAF | Test | Record_0198 | 17 |
a02W000000A8ShAIAV | Test | Record_0119 | 19 |
a02W000000A8ShBIAV | Test | Record_0159 | 0 |
a02W000000A8ShEIAV | Test | Record_0199 | 18 |
a02W000000A8ShCIAV | Test | Record_0139 | 12 |
a02W000000A8ShDIAV | Test | Record_0179 | 25 |
Now, after entering in my test tasks, each record should have increment by 1. Instead I got this:
Record ID | First Name | Last Name | Letter Counter |
a02W000000A8SgfIAF | Test | Record_0115 | 13 |
a02W000000A8SggIAF | Test | Record_0155 | 13 |
a02W000000A8SghIAF | Test | Record_0135 | 13 |
a02W000000A8SgiIAF | Test | Record_0175 | 13 |
a02W000000A8SgjIAF | Test | Record_0195 | 13 |
a02W000000A8SglIAF | Test | Record_0116 | 13 |
a02W000000A8SgmIAF | Test | Record_0156 | 13 |
a02W000000A8SgnIAF | Test | Record_0136 | 13 |
a02W000000A8SgoIAF | Test | Record_0176 | 13 |
a02W000000A8SgpIAF | Test | Record_0196 | 13 |
a02W000000A8SgqIAF | Test | Record_0117 | 13 |
a02W000000A8SgrIAF | Test | Record_0157 | 13 |
a02W000000A8SgsIAF | Test | Record_0137 | 13 |
a02W000000A8SgtIAF | Test | Record_0177 | 13 |
a02W000000A8SguIAF | Test | Record_0197 | 13 |
a02W000000A8Sh0IAF | Test | Record_0118 | 13 |
a02W000000A8Sh1IAF | Test | Record_0158 | 13 |
a02W000000A8Sh2IAF | Test | Record_0138 | 13 |
a02W000000A8Sh3IAF | Test | Record_0178 | 13 |
a02W000000A8Sh4IAF | Test | Record_0198 | 13 |
a02W000000A8ShAIAV | Test | Record_0119 | 13 |
a02W000000A8ShBIAV | Test | Record_0159 | 13 |
a02W000000A8ShEIAV | Test | Record_0199 | 13 |
a02W000000A8ShCIAV | Test | Record_0139 | 13 |
a02W000000A8ShDIAV | Test | Record_0179 | 13 |
Since I didn't want to include all 700 test records, another block of records had their Letter_counter__c field set to all 3s and another group all 11.
Any ideas what is happening?
Try this
All Answers
Try this
Thanks Avi,
That fixed it!
Hey Avi,
I ran into and issue.
The trigger works great. I wrote the test class and got 100% coverage. But when I upload it into Production and validate it, it fails and I get the following messages on those unrelated test classes:
Any thoughts as to what to do next?