You need to sign in to do that
Don't have an account?
Tatiana Cooke 9
Error regarding test class: "System.AssertException: Assertion Failed: Expected: 0, Actual 1"
Team,
I have the following trigger on my person accounts and am trying to run the below test class with the following error.
Error: "System.AssertException: Assertion Failed: Expected: 0, Actual: 1" on line 40 of my test class.
Appreciate any guidance.
Trigger:
I have the following trigger on my person accounts and am trying to run the below test class with the following error.
Error: "System.AssertException: Assertion Failed: Expected: 0, Actual: 1" on line 40 of my test class.
Appreciate any guidance.
Trigger:
trigger LogPersonAccountChange on Account (before delete, after insert, after undelete) { List<pi__ObjectChangeLog__c> logs = new List<pi__ObjectChangeLog__c>(); if (Trigger.new != null) { for (Account account : Trigger.new) { if (Account.PersonEmail != null && Account.PersonEmail != '') { pi__ObjectChangeLog__c log = new pi__ObjectChangeLog__c(); log.pi__ObjectFid__c = Account.PersonContactId; log.pi__ObjectType__c = 1; log.pi__ObjectEmail__c = Account.PersonEmail; if (System.Trigger.isInsert) { log.pi__ObjectState__c = 1; } else if (System.Trigger.isDelete) { log.pi__ObjectState__c = 2; } else if (System.Trigger.isUnDelete) { log.pi__ObjectState__c = 3; } logs.add(log); } } } else if (Trigger.old != null) { for (Account account : Trigger.old) { if (Account.PersonEmail != null && Account.PersonEmail != '') { pi__ObjectChangeLog__c log = new pi__ObjectChangeLog__c(); log.pi__ObjectFid__c = Account.PersonContactId ; log.pi__ObjectType__c = 1; log.pi__ObjectEmail__c = Account.PersonEmail; if (System.Trigger.isInsert) { log.pi__ObjectState__c = 1; } else if (System.Trigger.isDelete) { log.pi__ObjectState__c = 2; } else if (System.Trigger.isUnDelete) { log.pi__ObjectState__c = 3; } logs.add(log); } } } if (logs.size() > 0) { insert logs; } }Here is the test class:
/** * This class contains unit tests for validating the behavior of Apex classes * and triggers. * * Unit tests are class methods that verify whether a particular piece * of code is working properly. Unit test methods take no arguments, * commit no data to the database, and are flagged with the testMethod * keyword in the method definition. * * All test methods in an organization are executed whenever Apex code is deployed * to a production organization to confirm correctness, ensure code * coverage, and prevent regressions. All Apex classes are * required to have at least 75% code coverage in order to be deployed * to a production organization. In addition, all triggers must have some code coverage. * * The @isTest class annotation indicates this class only contains test * methods. Classes defined with the @isTest annotation do not count against * the organization size limit for all Apex scripts. * * See the Apex Language Reference for more information about Testing and Code Coverage. */ @isTest private class TestPersonAccountChangeLog { static testMethod void LogPersonAccountChangeTest() { String RecTypeId= [select Id from RecordType where (Name='Ward Residential Buyers') and (SobjectType='Account')].Id; WE_Process__c obj=new WE_Process__c(); obj.Name='test'; insert obj; Account account = new Account(); account.FirstName='Test Acc'; account.LastName='Last Name'; Account.PersonEmail = 'abc@123.com'; account.RecordTypeID=RecTypeId; insert Account; System.assertEquals([SELECT COUNT() FROM pi__ObjectChangeLog__c WHERE pi__ObjectEmail__c = :Account.PersonEmail AND pi__ObjectState__c = 1], 1); delete Account; System.assertEquals([SELECT COUNT() FROM pi__ObjectChangeLog__c WHERE pi__ObjectEmail__c = :Account.PersonEmail AND pi__ObjectState__c = 2], 1); undelete Account; System.assertEquals([SELECT COUNT() FROM pi__ObjectChangeLog__c WHERE pi__ObjectEmail__c = :Account.PersonEmail AND pi__ObjectState__c = 3], 1); } }
Create test data for pi__ObjectChangeLog__c ...
pi__ObjectChangeLog__c p1 = new pi__ObjectChangeLog__c ();
p1.name = 'fgasfsa';
p1.pi__ObjectState__c =1;
p1.pi__ObjectEmail__c = Account.PersonEmail;
Insert p1;
insert Account;
System.assertEquals(1, [SELECT COUNT() FROM pi__ObjectChangeLog__c WHERE pi__ObjectEmail__c = :Account.PersonEmail AND pi__ObjectState__c = 1]);
delete Account;
System.assertEquals(0, [SELECT COUNT() FROM pi__ObjectChangeLog__c WHERE pi__ObjectEmail__c = :Account.PersonEmail AND pi__ObjectState__c = 2]);
undelete Account;
System.assertEquals(1, [SELECT COUNT() FROM pi__ObjectChangeLog__c WHERE pi__ObjectEmail__c = :Account.PersonEmail AND pi__ObjectState__c = 3]);
Added both suggestions but am still getting error System.AssertException: Assertion Failed: Expected: 0, Actual: 1 on the line
System.assertEquals(1, [SELECT COUNT() FROM pi__ObjectChangeLog__c WHERE pi__ObjectEmail__c = :Account.PersonEmail AND pi__ObjectState__c = 1]);
Any thoughts?
pi__ObjectChangeLog__c p1 = new pi__ObjectChangeLog__c ();
p1.name = 'fgasfsa';
p1.pi__ObjectState__c = 1;
p1.pi__ObjectEmail__c = 'Account.PersonEmail';
p1.pi__ObjectFid__c = 'Sample Fid';
p1.pi__ObjectType__c = 1;
Insert p1;
p1.pi__ObjectEmail__c = Account.PersonEmail;
Below is the code line giving me issues.
System.assertEquals(1, [SELECT COUNT() FROM pi__ObjectChangeLog__c WHERE pi__ObjectEmail__c =:Account.PersonEmail AND pi__ObjectState__c = 3]);
System.assertEquals(1, [SELECT COUNT() FROM pi__ObjectChangeLog__c WHERE pi__ObjectEmail__c =:Account.PersonEmail AND pi__ObjectState__c = 1]);
/** * This class contains unit tests for validating the behavior of Apex classes * and triggers. * * Unit tests are class methods that verify whether a particular piece * of code is working properly. Unit test methods take no arguments, * commit no data to the database, and are flagged with the testMethod * keyword in the method definition. * * All test methods in an organization are executed whenever Apex code is deployed * to a production organization to confirm correctness, ensure code * coverage, and prevent regressions. All Apex classes are * required to have at least 75% code coverage in order to be deployed * to a production organization. In addition, all triggers must have some code coverage. * * The @isTest class annotation indicates this class only contains test * methods. Classes defined with the @isTest annotation do not count against * the organization size limit for all Apex scripts. * * See the Apex Language Reference for more information about Testing and Code Coverage. */
@isTest private class TestPersonAccountChangeLog {
static testMethod void LogPersonAccountChangeTest() {
String RecTypeId= [select Id from RecordType where (Name='Ward Residential Buyers') and (SobjectType='Account')].Id;
WE_Process__c obj=new WE_Process__c();
obj.Name='test'; insert obj;
Account account = new Account();
account.FirstName='Test Acc';
account.LastName='Last Name';
Account.PersonEmail = 'abc@123.com';
account.RecordTypeID=RecTypeId;
insert Account;
System.assertEquals(1, [SELECT COUNT() FROM pi__ObjectChangeLog__c WHERE pi__ObjectEmail__c = :Account.PersonEmail AND pi__ObjectState__c = 1]);
delete Account;
System.assertEquals(0, [SELECT COUNT() FROM pi__ObjectChangeLog__c WHERE pi__ObjectEmail__c = :Account.PersonEmail AND pi__ObjectState__c = 2]);
undelete Account;
System.assertEquals(1, [SELECT COUNT() FROM pi__ObjectChangeLog__c WHERE pi__ObjectEmail__c = :Account.PersonEmail AND pi__ObjectState__c = 3]);
}
}
@Deepak - Apparently you have to consider creating test data for
pi__ObjectChangeLog__c this cusotm object. I am pretty test class doesn't make sense without this.
Thanks
Below is the final error I am getting. Description Resource Path Location Type
System.ListException: List index out of bounds: 0 TestPersonAccountChangeLog.cls /Howard Hughes Production/src/classes line 3570 Force.com run test failure
I don't want to mess up my code since I'm so close. can someone help me solve this pls.
Updated my code to the below with some test data but am getting the following error. Should I be creating lists? please help!
Error:System.AssertException: Assertion Failed: Expected: 1, Actual: 2
System.assertEquals(2, [SELECT COUNT() FROM pi__ObjectChangeLog__c WHERE pi__ObjectEmail__c = :Account.PersonEmail AND pi__ObjectState__c = 1]);
System.ListException: List index out of bounds: 0 TestPersonAccountChangeLog.cls /Howard Hughes Production/src/classes line 3570 Force.com run test failure
Below is my updated code:
Please advise,
System.AssertException: Assertion Failed: Expected: 0, Actual: 1
What I am trying to do is set up a brand new conection between our new Pardot instance and our person accounts.
They gave me these instructions to follow: http://help.pardot.com/customer/en/portal/articles/2127277-setting-up-salesforce-person-accounts-for-pardot-syncing?b_id=11139
What am I doing wrong?
Do there need to be some records on the object change created?
We only have a partial sandbox but I have created the contection between pardot and our sandbox.
Please help!
Hi, this is a comment not an answer as this forum doesnt have this option, where you able to find an answer for this issue?
I start getting the same issue, the weird thing is that last week (when i did my last deployment) I didnt have this issue.