You need to sign in to do that
Don't have an account?
Adding a record type to a test class
Hi all,
I have a test class that I am trying to set a RecordTypeId to (see below). I need the record type id because I have a validation rule in production that will prevent the deployment of this test class without the record id set.
When I hardcode the recordId into the test class, I get 100% coverage. When I try to dynamically assign the id, however, I get 50% coverage.
Can anyone help with what I am doing wrong?
Thanks!
Tasia
@isTest
public class UpdateCaseWhenLeadConvertedTest
{
private static testMethod void LeadConvertedTest()
{
Lead olead = new Lead(LastName='Test',FirstName='Tester',Status='Known',Company='CD Test');
insert olead;
Case c = new case (Status ='New', Priority = 'Medium', Origin = 'Email');
c.Lead__c = olead.Id;
c.RecordTypeId = Schema.sObjectType.Case.getRecordTypeInfosByName().get('Customer_Service_Record_Type').getRecordTypeId();
insert c;
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(olead.id);
lc.setDoNotCreateOpportunity(true);
lc.setConvertedStatus('Converted w/out Opp');
Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
List<Case> lstCase = [Select id ,ContactId, Status, Type from Case where id =:c.id ];
System.assert(lstCase.size() > 0 );
System.assert(lstCase[0].ContactId !=null );
System.assertEquals('Closed', lstCase[0].Status);
System.assertEquals('Web Account Approved', lstCase[0].Type);
}
}
The "Schema.sObjectType.Case.getRecordTypeInfosByName().get('Customer_Service_Record_Type').getRecordTypeId();" routine searches for the recordTypeId by Label, check the language that is set by your test user in production and if the label name is the same in sanbox.
Att,
Eduardo B. Costa.
All Answers
The "Schema.sObjectType.Case.getRecordTypeInfosByName().get('Customer_Service_Record_Type').getRecordTypeId();" routine searches for the recordTypeId by Label, check the language that is set by your test user in production and if the label name is the same in sanbox.
Att,
Eduardo B. Costa.
That was it, I was using the Developer Name, not the Label.
Many thanks,
Tasia