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
Mubarak Hussain 1Mubarak Hussain 1 

RecordType in TestClass

Hi all,
How to include the following recordtypes in the testclass.

Apex Class.
for(case c:clist)
Id rtid=c.recordtypeId;

if(rtid=properties.New_record_type.id){
c.recordtypeId=properties.New_record_type.id;
}
elseif(rtid=properties.Old_record_type.id){
c.recordtypeId=properties.Old_record_type.id;

}
Thanks
Mubarak
 
Chandra Sekhar CH N VChandra Sekhar CH N V
While inserting case records in your test class, give recordTypeId = <yourRecordTypeID>. Insert case records for different scenarios so that it will cover else part as wel..
Vijay NagarathinamVijay Nagarathinam
Hi Mubarak,

Use the following code to use the recordtype id in test class.
 
RecordType rt = [SELECT id,Name FROM RecordType WHERE SobjectType = 'Case' and Name = 'Service Type' Limit 1];   
for(case c:clist) {
      c.RecordTypeId = rt.Id;
}

 
Vishal_GuptaVishal_Gupta
Hi Mubarak,

Please do query on your RecordType name, like this :

List<RecordType> rtypes = [SELECT Name, id FROM RecordType WHERE sObjectType='Object ApI name and Name = 'RecordTypeName';

Thanks,
Vishal
 
Mubarak Hussain 1Mubarak Hussain 1
Thank you for your replies...
Vijay NagarathinamVijay Nagarathinam
Hi Mubarak,

The above replies are resolve your issue , please choose the one as a best answer
Mubarak Hussain 1Mubarak Hussain 1
Hi vijay,
No, still am getting the same code coverage,that particular code parts is not covered
Vijay NagarathinamVijay Nagarathinam
Really, can you send me the code
Mubarak Hussain 1Mubarak Hussain 1
Hi vijay,
Now its covered.i made a small mistake while typing.
Thanks for your quick reply.