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
Vijay@sfdcVijay@sfdc 

Condition is not covering in test class

Hello All,
i have created test record  in test class, after i created record
for(account acc: alist)
{
  system.debug( '@@@@'+acc.recordtype.name); this values is null
system.debug( '$$$$'+acc.ischecked);  // this values true
 if(acc.recordtype.name=='Sample record type' & acc.ischecked==true)
  {
   // logic 
  //
 }
 in test class
 i have created record
 ex:
 testmethod ()
{
account acc= new acc( recordtypeid=// sme logic to fetch id
                                         name='ssssss' ,ischecked = true)
   insert  acc
}

with the above code i cant cover the condition  acc.recordtype.name=='Sample record type' , but data was inserted properly,

kindly tel me how to fix the above issue. please take it urgent.

thanks advance to all



 
Chris  ByromChris Byrom
I have never used recordtype.name before. I would use RecordTypeId instead like you do in the test class.
Vijay@sfdcVijay@sfdc
hello Vikram,

      what ever you have suggested i already done , inserted record in test class. even after insert record also   system.debug( '@@@@'+acc.recordtype.name) always returning NULL from the class
Amit Chaudhary 8Amit Chaudhary 8
I hope  you are fatching recordType.Name in query like below
List<Account> alist = [select id,ischecked , recordType.name from account];

for(account acc: alist)
{
  system.debug( '@@@@'+acc.recordtype.name); <b>this values is <u>null</u></b>
 system.debug( '$$$$'+acc.ischecked);  // <b>this values <u>true</u></b>
 
 if(acc.recordtype.name=='Sample record type' & acc.ischecked==true)
  {
  }
  
}

If not then please update your code like below and use recordTypeId only
Id accRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Sample record type').getRecordTypeId();
for(account acc: alist)
{
 
	if(acc.recordtypeId==accRecordTypeId && acc.ischecked==true )
	{
		
	}
}
Your Test class code should be like below
testmethod ()
{
Id accRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Sample record type').getRecordTypeId();

	account acc= new acc( recordtypeid=accRecordTypeId, name='ssssss' ,ischecked = true);
    insert  acc;
}


Let us know if this will help you

Thanks
Amit Chaudhary
 
Vijay@sfdcVijay@sfdc
In My class i condition like
for(account acc: alist)
{
  system.debug( '@@@@'+acc.recordtype.name); <b>this values is <u>null</u></b>
 system.debug( '$$$$'+acc.ischecked);  // <b>this values <u>true</u></b>
 
 if(acc.recordtype.name=='Sample record type' & acc.ischecked==true)
  {
  }
  
}

i have created test data for account , properly by includeing record type,

 
account acc= new account( recordtypeid=recordtypeid.getrecordtypeId(' samplerecordtype'),  name =xxxx, is cheacked = true )
List<Account> alist = [select id,ischecked , recordType.name from account];
even this test data i have created and queried  also also in the debug statements  record type id always displaying null
system.debug( '@@@@'+acc.recordtype.name); <b>this values is <u>null</u></b> system.debug( '$$$$'+acc.ischecked); // <b>this values <u>true</u></b>

my issue not yet soloved :( , kindly help me






 
Amit Chaudhary 8Amit Chaudhary 8
Please post your full code for Apex class and Test class
 
account acc= new account( recordtypeid=recordtypeid.getrecordtypeId(' samplerecordtype'),  name =xxxx, is cheacked = true );
insert acc;
List<Account> alist = [select id,ischecked , recordType.name from account];