You need to sign in to do that
Don't have an account?

Help with a simple test method on Event
Stuck with a test method for this trigger and I get the error:
Failure Message: "System.AssertException: Assertion Failed: Expected: Open, Actual: Open", Failure Stack Trace: "Class.testEventTrigger.test1: line 10, column 5 External entry point"
Here is the test method:
public class testEventTrigger { public static testMethod void test1() { List<Lead> leads = new List<Lead>{ new Lead(FirstName='Test 1',LastName='Test 1',Status='Open',Company='Test1',Sales_Cycle__c='Open'), new Lead(FirstName='Test 2',LastName='Test 2',Status='Open',Company='Test2',Sales_Cycle__c='Open') }; insert leads; List<Event> events = new List<Event>{ new Event(WhoId=Leads[0].Id,Subject='Tour',ActivityDate=System.today(), startdatetime=system.now(), Durationinminutes=60), new Event(WhoId=Leads[1].Id,Subject='Something Else',ActivityDate=System.today(), startdatetime=system.now(), Durationinminutes=60) }; insert events; Lead[] leadsgo = [select id,Sales_Cycle__c from lead where id in :leads]; System.assertEquals('Open',Leadsgo[1].Sales_Cycle__c); } }
And the trigger:
trigger tourchange on Event (before insert) { Set<Id> recordIds = new Set<Id>(); List<Lead> leadsToUpdate = new List<Lead>(); for(Event t:Trigger.new) if(t.subject=='tour' && t.Stages__c <> '30 days' && t.Stages__c <> '60 days') recordIds.add(t.whoid); leadsToUpdate = [select id from lead where id in :recordIds]; for(Lead l:leadsToUpdate) L.sales_cycle__C = 'Tour Scheduled'; update leadsToUpdate; }
THANKS!
B
Wow, that's not an easy one to decipher but I think I figured it out. If you take the value of 'Open' that you have in the test where you create the lead and paste it into a character identifier resource like this:
http://software.hixie.ch/utilities/cgi/unicode-decoder/character-identifier
You'll see there are actually some apparently hidden characters in the value which are causing the equality check to fail. Not sure how you got that value in there but update your code by manually typing over the values with 'Open' in each location. Alternatively define a string variable and use it instead. Either change should make your test pass.
All Answers
Wow, that's not an easy one to decipher but I think I figured it out. If you take the value of 'Open' that you have in the test where you create the lead and paste it into a character identifier resource like this:
http://software.hixie.ch/utilities/cgi/unicode-decoder/character-identifier
You'll see there are actually some apparently hidden characters in the value which are causing the equality check to fail. Not sure how you got that value in there but update your code by manually typing over the values with 'Open' in each location. Alternatively define a string variable and use it instead. Either change should make your test pass.
Wow for sure... Never thought of that and would be cooking my brain still. Thanks a lot as it worked beautifully after just typing 'Open'. Before, I copied and pasted from the code itself... really have no clue why did it change characters..
Anyways, thanks a lot. having a issue with a very similar trigger and test method. Triied many logics on the System. assert or System.assertEquals, but not working. here is the test:
And the trigger:
Thanks a lot. I've been learning Apex and all help is appreciated!
Never mind.... used:
System.assertEquals(leadsgo[0].ownerid,tasksgo[0].whoid);
and it seems to work.
B