I am new to Test Classes. My Scenario is Account has child object as Address. When a new record is inserted into the child object it should be reflected in the detail page. When I tried writing test class I got the following error:
Invalid conversion from runtime type SOBJECT:Account_Address__c to SOBJECT:Account
test class is as follows
@isTest public className{
public testMethodName(){
account creation;
insert account;
childclass(address) creation;
insert childclass;
ApexPages.StandardController cntrl = new ApexPages.StandardController(compadd);
AccountAddressController aac = new ICB_AccountAddressController(cntrl);
How to solve this mismatch.........how can i map the new address created to the account record created?
hi Naved Khan,
Full Code is As follows@isTest public class CompanyRecordInsertion{
static testMethod void insertCompanyAddress(){
Account company = new Account(Name ='TestCompany1',Class__c='Unclassed',Cov_Sector__c='IFI',Company_Status__c='Active',Type='Other Relationship',Relationship_Status__c='Important',Cov_SubSector__c='IFI',IConnection__c='12345');
insert company;
//Company record insertion
Company_Address__c compadd = new Company_Address__c(Company__c =
company.id,Address__c='#444,4th Floor,J building,2nd Cross',City__c='NiagaraFalls',Countries__c='Canada',Prov_State__c='Ontario',Postal_Code_Zip__c='456123',Primary_Head_Quarter__c=false);
insert compadd;
ApexPages.StandardController cntrl = new ApexPages.StandardController(compadd);
AccountAddressController aac = new AccountAddressController(cntrl);
aac.callsave();
aac.activityRedirect();
PageReference ref1 =new PageReference('/apex/AccountAddressPage?bnShowAll=true');
Test.setCurrentPage(ref1);
AccountAddressController aac1 = new AccountAddressController(cntrl);
aac1.callsave();
aac.activityRedirect();
}
}