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
Naresh.soft12Naresh.soft12 

i want test class for my code

Hi,
can one help me .i want test class for my code

public class WrapperClassController 
{
    public List<AccountWrapper> accWrapList{get; set;}
    String queryString = 'Select Name, Type, BillingCity, BillingState, BillingCountry from Account order by Name';
    
    public WrapperClassController()
    {
        accWrapList = new List<AccountWrapper>();
        for(Account iter :Database.query(queryString))
        {
            accWrapList.add(new AccountWrapper(iter.Name,iter.Type,iter.BillingCity,iter.BillingState,iter.BillingCountry));
        }
        
        for(Contact iter :[SELECT LastName FROM Contact LIMIT 5])
        {
            accWrapList.add(new AccountWrapper(iter.LastName,null,null,null,null));
        }
    }
    
    public PageReference ProceedAction()
    {
        for(AccountWrapper iter :accWrapList)
        {
            if(iter.isSelected)
            {
            //Do necessary customization
            }
        }
        return null;
    }
    
    public class AccountWrapper
    {
        public String accName{get; set;}
        public String accType{get; set;}
        public String accCity{get; set;}
        public String accState{get; set;}
        public String accCtry{get; set;}
        public Boolean isSelected{get; set;}
        public String accRecId{get; set;}
        
        public AccountWrapper(String accName, String accType, String accCity, String accState, String accCtry)
        {
            this.accName = accName;
            this.accType = accType;
            this.accCity = accCity;
            this.accState = accState;
            this.accCtry = accCtry;
            this.accRecId = accRecId;
            isSelected = false;
        }
    }
}
Sagar LakhaniSagar Lakhani

Hi Naresh,


Please try below code. you get 100% code coverage.


@isTest
public class TestAccountWrapper {
    static testMethod void testAccWra(){
        
        Account objAccount  = new Account();
        objAccount.Name = 'TestName';
        objAccount.Type = 'TestType';
        objAccount.BillingCity = 'Ahm';
        objAccount.BillingState = 'Guj';
        objAccount.BillingCountry = 'Ind';
        insert objaccount;
        
        Contact objContact  = new Contact();
        objContact.LastName = 'TestLastName';
        insert objContact;
        
        WrapperClassController.AccountWrapper wrapAcc = new WrapperClassController.AccountWrapper(objAccount.Name,objAccount.Type,objAccount.BillingCity,objAccount.BillingState,objAccount.BillingCountry);
        WrapperClassController controller = new WrapperClassController();
        controller.ProceedAction();
    }
}


Thanks,
Sagar Lakhani

roy mathew 9roy mathew 9
thank you mr Sagar Lakhani , its working  100 % thanks alote...actually this code implimented for my mobile app development (http://www.codeaqatar.com/mobile-development) websites any way its working thanks alote 
Sagar LakhaniSagar Lakhani

You're welcome anytime roy.....

 

Thanks,
Sagar Lakhani