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
Shruthi GM 4Shruthi GM 4 

How to write test class for the below class?

public with sharing class AccountSelectClassController{
//Our collection of the class/wrapper objects wrapAccount
public List<wrapAccount> wrapAccountList {get; set;}
public List<Account> selectedAccounts{get;set;}


public AccountSelectClassController(){
if(wrapAccountList == null) {
wrapAccountList = new List<wrapAccount>();
for(Account a: [select Id, Name from Account limit 25]) {
// As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
wrapAccountList.add(new wrapAccount(a));
}
}

}
public void processSelected() {
selectedAccounts = new List<Account>();
for(wrapAccount wrapAccountObj : wrapAccountList) {
if(wrapAccountObj.selected == true) {
selectedAccounts.add(wrapAccountObj.acc);
 }

        }

    }
    }

Please help!!!
Best Answer chosen by Shruthi GM 4
sfdcMonkey.comsfdcMonkey.com
hi Shruthi
try below code, you have 100% code coverage for both class
@isTest
private class TestAccount {

    @isTest static void testMethodSample() {
        
        Account acc = new Account();
        acc.Name = 'test';
        // all account requerd fields 
        insert acc ;
        
        AccountSelectClassController obj = new AccountSelectClassController();
        obj.wrapAccountList[0].selected = true;
        
        obj.processSelected();
        
    }
    
}
Thanks
let me inform if it helps you and mark your qiestion as solved :)


 

All Answers

Shruthi GM 4Shruthi GM 4
public class wrapAccount {

public Account acc {get; set;}
public Boolean selected {get; set;}

public wrapAccount(Account a) {
acc = a;
selected =selected ;

}
}
sfdcMonkey.comsfdcMonkey.com
hi Shruthi
try below code, you have 100% code coverage for both class
@isTest
private class TestAccount {

    @isTest static void testMethodSample() {
        
        Account acc = new Account();
        acc.Name = 'test';
        // all account requerd fields 
        insert acc ;
        
        AccountSelectClassController obj = new AccountSelectClassController();
        obj.wrapAccountList[0].selected = true;
        
        obj.processSelected();
        
    }
    
}
Thanks
let me inform if it helps you and mark your qiestion as solved :)


 
This was selected as the best answer
Shruthi GM 4Shruthi GM 4
thank you..it worked..:)
Shruthi GM 4Shruthi GM 4
But both the classes are not covered!!!...how to write test class for the wrapper class?
sfdcMonkey.comsfdcMonkey.com
by above test class you have both class covered 100%  go to developer console and run the test class and check both class covrage
 
Shruthi GM 4Shruthi GM 4
Sorry I did run the class and checked.100% coverage is there for both the classes.
Thank you...:)