I have a trigger on Account that inserts into Property after insert and I am have trouble with the test class. I'm not sure how to handle it since I am new to Apex.
Here is the trigger.
trigger CreatePropertRecord on Account (after Insert) {
for(Account a : trigger.new)
if( a.Number_of_Properties__c > 0 )
{
Property__c v = new Property__c ();
if( a.Property_Name__c <> Null )
v.Name = a.Property_Name__c;
Else
v.Name = a.Name;
v.Property__c = a.id ;
v.Property_Code__c = a.Property_ID__c ;
v.Bathrooms_Number__c= a.Number_Bathrooms__c;
v.Bedrooms_Number__c= a.Bedrooms_Number__c;
v.Beach_Front__c = a.Beach_Front__c ;
v.Street__c = a.Street__c;
v.City__c = a.City__c;
v.State_Province__c = a.State_Province__c;
v.Zip_Postal_Code__c = a.Zip_Postal_Code__c;
v.Country__c = a.Country__c;
v.Ski_In_Ski_Out__c = a.Ski_In_Ski_Out__c ;
v.Resort__c = a.Resort__c;
v.Property_Type__c = a.Property_Type__c;
v.Number_of_Properties__c = a.Number_of_Properties__c;
v.Ownership_Status__c = a.Ownership_Status__c ;
v.Property_Owner_Status__c = a.Property_Owner_Status__c;
v.Expected_Annual_GLR__c = a.Expected_Annual_GLR__c;
insert v ;
}}
Here is the test class that was created that is not working.
@isTest
private class CreatePropertRecordTest {
static testMethod void validateCreatePropertRecord() {
account a = new account(
a.Property_Name__c='test name',
a.Property_ID__c='test id',
a.Number_Bathrooms__c='1B',
a.Bedrooms_Number__c='1B',
a.Beach_Front__c=TRUE,
a.Street__c='test street',
a.City__c='test city',
a.State_Province__c='test state',
a.Zip_Postal_Code__c='test zip',
a.Country__c='test country',
a.Ski_In_Ski_Out__c=TRUE,
a.Resort__c='test resort',
a.Property_Type__c='Cabin',
a.Number_of_Properties__c=1,
a.Ownership_Status__c='Already own',
a.Property_Owner_Status__c='LLC',
a.Expected_Annual_GLR__c='50000'
);
// Insert account
insert a;
// Retrieve the new account
a = [SELECT description FROM account WHERE Id =:a.Id];
// Test that the trigger correctly updated the description
System.assertEquals(null, a.description);
}}