+ Start a Discussion
Micky MMicky M 

Record Type

Hi all does anyone know how i do a comparison on a record type name?

 

My test method is failing because this bit is never true:

 

if(opportunity.RecordType.Name == 'MDS')

 

and when i look in the debug log is if i do

 

system.debug('opportunity.RecordType.Name = ' + opportunity.RecordType.Name);

 

then all i see is null, but my test opportunit has a recored type, this is how i set the opp up:

 

        opportunity3 = new Opportunity(Name = 'Test3', AccountId = account.Id, StageName = 'Final Contract Issued', Probability = 95, CloseDate = Date.today(), MCS_Commercials_Approved__c = true, HLD_created__c = 'HLD signed off', RecordTypeId = [select id, DeveloperName, Name from RecordType where Name = 'MDS' and sObjecttype = 'Opportunity' limit 1].id);        

This is driving me crazy, Thanks All

Best Answer chosen by Admin (Salesforce Developers) 
AshishyadavAshishyadav
or ill suggest do this way
recordtype rt = [select id, DeveloperName, Name from RecordType where Name = 'MDS' and sObjecttype = 'Opportunity' limit 1];

now use rt
opportunity3 = new Opportunity(_________ RecordTypeId = rt.id);

i hope it works

All Answers

AshishyadavAshishyadav

try using ID of that record type

RecordtypeId

AshishyadavAshishyadav
or ill suggest do this way
recordtype rt = [select id, DeveloperName, Name from RecordType where Name = 'MDS' and sObjecttype = 'Opportunity' limit 1];

now use rt
opportunity3 = new Opportunity(_________ RecordTypeId = rt.id);

i hope it works
This was selected as the best answer
Micky MMicky M

Yeah thanks guys thats got it, i just needed to use the id rather than trying to use a string.