You need to sign in to do that
Don't have an account?
Trigger to Update Account when Task Logged
Hey Guys,
Been busy, writing my second ever Trigger.
This one is a bit more complex than my first, but no where near advanced.
What I am trying to do, is when a task with 'purpose' X or Y is logged, it takes the Description field and adds it to a custom field in the Account.
My Trigger is:
trigger LoworProCommunicationLoggingAutomated on Task (after insert) { Set<Id> acctIds = new Set<Id>(); String DescToUpdate; String Purp; for(Task t: [SELECT Subject, WhatId, Status, Purpose__c, Description FROM TASK WHERE ID IN:trigger.new]){ String wId = t.WhatId; if(wId!=null && wId.startsWith('001') && !acctIds.contains(t.WhatId) && t.Status == 'Completed' && (t.Purpose__c.Equals('Proactive Communication') || t.Purpose__c.Equals('Low-Redemption Communication'))){ acctIds.add(t.WhatId); DescToUpdate = t.Description; Purp = t.Purpose__c; } } for(Account a:[SELECT Low_Redemption_Notes__c, Proactive_Communication_Notes__c FROM Account WHERE ID IN:acctIds]){ if(Purp == 'Proactive Communication'){ a.Proactive_Communication_Notes__c = DesctoUpdate; update a; } else if (Purp == 'Low-Redemption Communication'){ a.Proactive_Communication_Notes__c = DesctoUpdate; a.Low_Redemption_Notes__c = DesctoUpdate; update a; } } }
My Test Class is:
@isTest private class LowProCommTest { static testMethod void myUnitTest() { // TO DO: implement unit test Account a = new Account(name='Test'); insert a; Task t = new Task(subject='Test Activity', Status = 'Completed', Purpose__c = 'Proactive Communication', Description = 'I have Called This Dealership', whatId = a.id); insert t; a = [SELECT ID, Low_Redemption_Notes__c, Proactive_Communication_Notes__c FROM Account WHERE ID = :a.id]; System.assertEquals(t.Description, a.Proactive_Communication_Notes__c); } }
Obviously, I have 0% coverage on my code.
However, before I attack that, I am running in to an issue that the notes field and the description are not equal as evidenced by my system.assertequals throwin an error.
I would love an actual description as to what I am doing wrong here so I can keep learning.
Stupid, stupid mistake... Had to change
' to "
All Answers
Still working on this, I believe i need to completely re-attack this problem and start from a different angle.
I am missing any sort of mapping for the account values and in general, have some very poor practice in this code
So, I re-wrote a lot of my code and am still having some issues. I suck at Test Classes
Trigger:
Test Class:
Issues: Still getting an Assertion Failure: t.description and a.Low_Redemption_Notes don't match.
Still not test coverage.
Can someone give me some assistance? Still a huge n00b
Stupid, stupid mistake... Had to change
' to "