You need to sign in to do that
Don't have an account?
Tatiana Cooke 9
When trying to test person account insertion: System.AssertException: Assertion Failed: Expected: 2, Actual: 1
Team,
keep getting errors when trying to insert an account for a test class.
Error:
System.AssertException: Assertion Failed: Expected: 2, Actual: 1
New to coding so don't understand the error. I am trying to set up trigger that creates a change log record every time the person account email is changed.
keep getting errors when trying to insert an account for a test class.
Error:
System.AssertException: Assertion Failed: Expected: 2, Actual: 1
New to coding so don't understand the error. I am trying to set up trigger that creates a change log record every time the person account email is changed.
@isTest private class TestPersonAccountChangeLog { static testMethod void LogPersonAccountChangeTest() { RecordType personAccountRecordType = [SELECT Id FROM RecordType WHERE Name = 'Ward Residential Buyers' and SObjectType = 'Account']; User thisUser = [ select Id from User where Id = :UserInfo.getUserId() ]; System.runAs ( thisUser ) { WE_Process__c obj=new WE_Process__c(); obj.Name='test'; insert obj; Account a = NEW Account(); a.FirstName='John'; a.LastName='DoeTest1'; a.PersonEmail = 'doetest1@test.com'; a.RecordType = personAccountRecordType; insert a; System.assertEquals(2, [SELECT COUNT() FROM pi__ObjectChangeLog__c WHERE pi__ObjectEmail__c = :A.PersonEmail AND pi__ObjectState__c = 1]); delete A; System.assertEquals(0, [SELECT COUNT() FROM pi__ObjectChangeLog__c WHERE pi__ObjectEmail__c = :A.PersonEmail AND pi__ObjectState__c = 2]); undelete A; System.assertEquals(1, [SELECT COUNT() FROM pi__ObjectChangeLog__c WHERE pi__ObjectEmail__c = :A.PersonEmail AND pi__ObjectState__c = 3]); } }}
Just comment the assert that will work. But that is not a prefect solution
Here is my code:
Thank you for helping!
This will work for you try this!
Thank you!
Now that I updated the code it is saying Error:
System.AssertException: Assertion Failed: Expected: 0, Actual: 1
On the second assertion = (. Any ideas?
Error:
System.ListException: List index out of bounds: 0
Got the following error:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, entity type cannot be inserted: Person Account: []
How do I troubleshoot why it won't insert?
Replace 6th line with the below
Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
Thank you so much for your continued help and support. I have another meeting today with the business and I want to report that this is completed.
The system administrator changes worked but now I am getting the below error:
System.QueryException: List has no rows for assignment to SObject.
How do I resolve?