function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Akansha GuptaAkansha 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);
    } 
    
    
}
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Akansha Gupta, Please follow below Salesforce Best Practice  Link on Test Classes:- I hope it will be helpful.

Please mark it as best answer if the information is informative.

Best Regards
Rahul Kumar