You need to sign in to do that
Don't have an account?
Timothy Smith
Assert Equals not working as expected.
On the Opportunity I have Primary_Contact__c and Secondary_Contact__c.
Contact has 3 phone numbers with 'Do Not Call' status field corresponding
phone_c and phone__status__c
work_phone__c and work_phone_status
mobile_phone__c and mobile_phone_status
Anytime a Contact is Insert/Updated the Trigger will check any opportunity where this contact is associated. Trigger will check both Primary_Contact and Secondary_Contact__c of Opportunity for a valid phone number. If field is blank or status is "Do Not Call" this is considered a bad number. For any Opportunity where a good number does not exist, close the opportunity.
I have the Trigger and Test running ok. The test Opportunity should be closed. System.debug at the end shows Opportunity was closed but AssertEquals does not agree.
Trigger:
Test Class
Contact has 3 phone numbers with 'Do Not Call' status field corresponding
phone_c and phone__status__c
work_phone__c and work_phone_status
mobile_phone__c and mobile_phone_status
Anytime a Contact is Insert/Updated the Trigger will check any opportunity where this contact is associated. Trigger will check both Primary_Contact and Secondary_Contact__c of Opportunity for a valid phone number. If field is blank or status is "Do Not Call" this is considered a bad number. For any Opportunity where a good number does not exist, close the opportunity.
I have the Trigger and Test running ok. The test Opportunity should be closed. System.debug at the end shows Opportunity was closed but AssertEquals does not agree.
Trigger:
trigger Contact_DNC_Opportunity on Contact (after insert, after update){ List<Opportunity> OpportunitiesToClose = new List<Opportunity>(); List<Opportunity> WorkingOpportunities = [SELECT StageName, Primary_Contact__c, Secondary_Contact__c, Primary_Contact__r.Phone_Status__c, Primary_Contact__r.Mobile_Phone_Status__c, Primary_Contact__r.Work_Phone_Status__c, Primary_Contact__r.Phone, Primary_Contact__r.Normalized_Mobile_Phone__c, Primary_Contact__r.Normalized_Work_Phone__c, Secondary_Contact__r.Phone_Status__c, Secondary_Contact__r.Mobile_Phone_Status__c, Secondary_Contact__r.Work_Phone_Status__c, Secondary_Contact__r.Phone, Secondary_Contact__r.Normalized_Mobile_Phone__c, Secondary_Contact__r.Normalized_Work_Phone__c FROM Opportunity WHERE Primary_Contact__c In :Trigger.New OR Secondary_Contact__c In :Trigger.New ]; System.debug('Before Insertion' + WorkingOpportunities); for(Opportunity opp: WorkingOpportunities){ //Check Primary Contact phone numbers if ((opp.Primary_Contact__r.Phone == Null) || (opp.Primary_Contact__r.Phone_Status__c == 'Do Not Call')&& (opp.Primary_Contact__r.Normalized_Mobile_Phone__c == Null) || (opp.Primary_Contact__r.Mobile_Phone_Status__c == 'Do Not Call')&& (opp.Primary_Contact__r.Normalized_Work_Phone__c == Null) || (opp.Primary_Contact__r.Work_Phone_Status__c == 'Do Not Call')&& (opp.Secondary_Contact__r.Phone == Null) || (opp.Secondary_Contact__r.Phone_Status__c == 'Do Not Call')&& (opp.Secondary_Contact__r.Normalized_Mobile_Phone__c == Null) || (opp.Secondary_Contact__r.Mobile_Phone_Status__c == 'Do Not Call')&& (opp.Secondary_Contact__r.Normalized_Work_Phone__c == Null) || (opp.Secondary_Contact__r.Work_Phone_Status__c == 'Do Not Call') ) { //Add opp to List if fits criteria opportunitiesToClose.add(opp); } } for (Opportunity opp1 : opportunitiesToClose){ opp1.StageName = 'Closed Lost'; } if(opportunitiesToClose.size() > 0){ update opportunitiesToClose; System.debug('After Insert' + opportunitiesToClose); //This shows the "Closed Lost" change that is expected but the Assert.Equals statement in Test Class see 'Ready to Call/Schedule' } }
Test Class
@isTest private class ContactDNCOpportunityTest { private static testMethod void testCloseOpps(){ //Create Account Account newAcc = FlowTestUtils.createHouseholdAccount(); insert newAcc; //Create Contacts List<Contact> conList = new List<Contact> { new Contact(FirstName='test1',LastName='tester',AccountId = newAcc.Id, Email = 'test1@testing.com', Phone = '1234567891', Phone_Status__c = 'Do Not Call'), //Has Phone Number - Do not call, Closed Opp new Contact(FirstName='test2',LastName='tester',AccountId = newAcc.Id, Email = 'test2@testing.com'), //Blank No Numbers Closed Opp new Contact(FirstName='test3',LastName='tester',AccountId = newAcc.Id, Email = 'test3@testing.com', Normalized_Work_Phone__c = '1234567891',Work_Phone_Status__c = 'Active'), // Has Work Number, Active, Close Opp new Contact(FirstName='test4',LastName='tester',AccountId = newAcc.Id, Email = 'test4@testing.com', Phone = '1234567891', Phone_Status__c = 'Active'), //Has Phone Number, Active, Do not Close Opp new Contact(FirstName='test5',LastName='tester',AccountId = newAcc.Id, Email = 'test5@testing.com', Normalized_Mobile_Phone__c = '1234567891', Mobile_Phone_Status__c = 'Do Not Call'), //Has mobile number, DNC, Close Opp new Contact(FirstName='test6',LastName='tester',AccountId = newAcc.Id, Email = 'test6@testing.com', Normalized_Work_Phone__c = '1234567891', Work_Phone_Status__c = 'Do Not Call') //Has Worknumber DNC is checked }; insert conList; List<Opportunity> oppList = new List<Opportunity>(); Opportunity opptest1 = new Opportunity(Name = 'Opp1', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test1'].id); oppList.add(opptest1); Opportunity opptest2 = new Opportunity(Name = 'Opp2', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test2'].id); oppList.add(opptest2); Opportunity opptest3 = new Opportunity(Name = 'Opp3', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test3'].id); oppList.add(opptest3); Opportunity opptest4 = new Opportunity(Name = 'Opp4', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test4'].id); oppList.add(opptest4); Opportunity opptest5 = new Opportunity(Name = 'Opp5', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test5'].id); oppList.add(opptest5); Opportunity opptest6 = new Opportunity(Name = 'Opp6', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test6'].id); oppList.add(opptest6); Opportunity opptest7 = new Opportunity(Name = 'Opp7', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today()); oppList.add(opptest7); insert oppList; Test.StartTest(); update conList; Test.stopTest(); // Assert Statements System.assertEquals('Closed Lost', opptest1.StageName); //This fails. StageName = 'Ready to Call/Schedule' /* System.assertEquals('Closed Lost', opptest2.StageName); System.assertEquals('Closed Lost', opptest3.StageName); System.assertEquals('Closed Lost', opptest4.StageName); System.assertEquals('Closed Lost', opptest5.StageName); System.assertEquals('Closed Lost', opptest6.StageName); System.assertEquals('Closed Lost', opptest7.StageName); */ } }
What is the error you are seeing and in which line of your test class?