You need to sign in to do that
Don't have an account?
John Neilan
Record Type Name in Test Class
I have a test class that creates records for use in unit tests. One of the components creates an Opportunity record, but I don't know how to add a Record Type to the Opp. I know I can use RecordTypeID, but since I don't want to hardcode that, I am looking to use the Record Type name. Can anyone help me figure out the syntax I need to use? Thanks,
public static Opportunity createOppNew (Id acctId){ Opportunity opp1 = new Opportunity(); opp1.Name = 'Test Renewal Opp'; opp1.StageName = 'Phase 1'; opp1.CloseDate = Date.today().addYears(1); opp1.Renewal__c = 'Yes'; opp1.Effective_Date__c = Date.today().addYears(1); opp1.RP_Contract_Start__c = Date.today().addDays(1); opp1.Term__c = 12; opp1.AccountId = acctId; opp1.RP_Customer_Engagement__c = 0; return opp1; }
you can use
recordtype rc1 = [SELECT Id FROM RecordType WHERE SObjectType = 'Opportunity' limit 1];
Opportunity oppty = new Opportunity();
oppty.recordtype = rc1.id;
regards,
Yesha
All Answers
you can use
recordtype rc1 = [SELECT Id FROM RecordType WHERE SObjectType = 'Opportunity' limit 1];
Opportunity oppty = new Opportunity();
oppty.recordtype = rc1.id;
regards,
Yesha