You need to sign in to do that
Don't have an account?
Akansha Gupta
Test class for controller class
Hi! Can someone help me with the test class for the following controller class
public with sharing class VFC92_BillingAddListController {
public string id,Account;
public list<Account_Billing_Address__c> SelectedAccount { get; set; }
public Account CurrentAccount {get; set;}
public String AccountName {get; set;}
public Account_Billing_Address__c Address;
public TR1__Closing_Report__c cr = new TR1__Closing_Report__c();
public Id AccountId{get;set;}
public VFC92_BillingAddListController()
{
Account = ApexPages.currentPage().getParameters().get('Account');
CurrentAccount = [Select Headquarters_Flag__c,ParentId from Account where Id =: Account];
if(CurrentAccount.Headquarters_Flag__c)
{
SelectedAccount = [SELECT Id,Name FROM Account_Billing_Address__c
where Status__c = 'Active' AND Account__c =: Account];
AccountId = Account;
}
else
{
SelectedAccount = [SELECT Id,Name FROM Account_Billing_Address__c
where Status__c = 'Active' AND Account__c =: CurrentAccount.ParentId];
AccountId = CurrentAccount.ParentId;
}
id = ApexPages.currentPage().getParameters().get('id');
}
public PageReference cancel()
{
return new PageReference('/' + id).setRedirect(true);
}
public PageReference create()
{
PageReference pr = new PageReference('/apex/VFP93_CreateNewBillingAddress?closingreport='+id+'&accountid='+AccountId);
return pr;
}
public PageReference save()
{
return new PageReference('/' + id).setRedirect(true);
}
public PageReference elect()
{
Address = [Select Billing_City__c,Billing_Street__c,Billing_State_Province__c,Billing_Zip_Postal_Code__c
from Account_Billing_Address__c
where name =:AccountName AND Account__c =: AccountId ];
cr.Id = id;
cr.TR1__Billing_City__c = Address.Billing_City__c;
cr.TR1__Billing_State__c = Address.Billing_State_Province__c;
cr.TR1__Billing_Street__c = Address.Billing_Street__c;
cr.TR1__Billing_Zip_Code__c = Address.Billing_Zip_Postal_Code__c;
update cr;
return new PageReference('/' + id).setRedirect(true);
}
}
public with sharing class VFC92_BillingAddListController {
public string id,Account;
public list<Account_Billing_Address__c> SelectedAccount { get; set; }
public Account CurrentAccount {get; set;}
public String AccountName {get; set;}
public Account_Billing_Address__c Address;
public TR1__Closing_Report__c cr = new TR1__Closing_Report__c();
public Id AccountId{get;set;}
public VFC92_BillingAddListController()
{
Account = ApexPages.currentPage().getParameters().get('Account');
CurrentAccount = [Select Headquarters_Flag__c,ParentId from Account where Id =: Account];
if(CurrentAccount.Headquarters_Flag__c)
{
SelectedAccount = [SELECT Id,Name FROM Account_Billing_Address__c
where Status__c = 'Active' AND Account__c =: Account];
AccountId = Account;
}
else
{
SelectedAccount = [SELECT Id,Name FROM Account_Billing_Address__c
where Status__c = 'Active' AND Account__c =: CurrentAccount.ParentId];
AccountId = CurrentAccount.ParentId;
}
id = ApexPages.currentPage().getParameters().get('id');
}
public PageReference cancel()
{
return new PageReference('/' + id).setRedirect(true);
}
public PageReference create()
{
PageReference pr = new PageReference('/apex/VFP93_CreateNewBillingAddress?closingreport='+id+'&accountid='+AccountId);
return pr;
}
public PageReference save()
{
return new PageReference('/' + id).setRedirect(true);
}
public PageReference elect()
{
Address = [Select Billing_City__c,Billing_Street__c,Billing_State_Province__c,Billing_Zip_Postal_Code__c
from Account_Billing_Address__c
where name =:AccountName AND Account__c =: AccountId ];
cr.Id = id;
cr.TR1__Billing_City__c = Address.Billing_City__c;
cr.TR1__Billing_State__c = Address.Billing_State_Province__c;
cr.TR1__Billing_Street__c = Address.Billing_Street__c;
cr.TR1__Billing_Zip_Code__c = Address.Billing_Zip_Postal_Code__c;
update cr;
return new PageReference('/' + id).setRedirect(true);
}
}
- please check for Test Class Generator App from APP Exchange.Please refer the below link.
- https://appexchange.salesforce.com/listingDetail?listingId=a0N3A00000EFozgUAD
- I will recommend you to start using trailhead to learn about test classes.
- https://trailhead.salesforce.com/modules/apex_testing (https://trailhead.salesforce.com/modules/apex_testing )
Please follow below Salesforce Best Practice Link on Test Classes:-- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm (http://https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm)
- http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
I hope it will be helpful.Please mark it as best answer if the information is informative.
Best Regards
Rahul Kumar