[SalesForce] record type name insert in test class

  • Record Type Label: Lead/Opportunity Rule
  • Record Type Name: Lead_Opportunity_Rule

throw an error Compile Error: Initial term of field expression must be
a concrete SObject: String

 String recType = Schema.SObjectType.Assignment__c.getRecordTypeInfosByName().get('Lead_Opportunity_Rule').getRecordTypeId();
             //Assignment Record
                Assignment__c objass = new Assignment__c();
                objass.FE_Code__c = fobj.id;
                objass.Partner_ID__c = fobj.id;
                objass.Lead_Rule_Type__c = 'PartnerID';
                objass.RecordType = recType.name;
                insert objass;

Best Answer

You get record type Id, you cannot extract name from it.

RecordType rt = [SELECT Id FROM RecordType WHERE sObjectType = 'Assignment__c' AND Name = 'Lead_Opportunity_Rule'];
...
objass.RecordType = rt;
// OR
objass.RecordTypeId = rt.Id;
Related Topic