You need to sign in to do that
Don't have an account?

RecordType.Name in Test Methods
So I'm I'm writing a test method for some code that queries RecordType.Name on the Opportunity object. I'm able to grab the RecordType ID and assign it to the Opportunity. System.debug shows that the RecordType I query in the test method has an ID and Name as well.
For some reason, it's telling me that Opportunity.RecordType.Name is null, even after I've assigned a RecordType to the Opportunity. Anyone know what's going wrong here? Here's the code:
RecordType UpsellRT = [SELECT Id,Name FROM RecordType WHERE sObjectType = 'Opportunity' AND Name = 'UpSell' LIMIT 1];
Opportunity OPP = new Opportunity(
Name = 'Test Opp',
RecordTypeId = UpsellRT.Id,
CloseDate = Date.valueOf('2013-01-01'),
StageName = 'Closed Won');
insert OPP;
Yeah, it queries RecordType.Name in the actual code being tested.
This is what System Debug tells me:
System.debug(OPP.RecordTypeId) returns an ID value
System.debug(OPP.RecordType.Name) returns null
The record type query is definitely finding a record type and assigning the ID to the Opportunity, but the name field is still null when I try to do anything with it.
have you assigned
@istest as @istest(seeAllData = true)
here my record type name is RFP in opportunity object.
for example below code is for Record type call in Testclass
RecordType RFPRectype = [select id,DeveloperName from RecordType where RecordType.DeveloperName ='RFP'];
CLASSName.opportunity.RecordTypeId = RFPRectype.id;
paste your full code. including @istest .