1
  • 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;
1

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;
  • i tried this but it throw an error that List has no rows – cloudZigZag Nov 3 '16 at 5:16
  • Use DeveloperName instead of Name – Jean-Philippe Leclerc Jan 28 at 21:11
4

You should assign the lookup as follows:

objPass.RecordTypeId = recType;

A String instance does not have the Name property.

You might confuse yourself less with clearer naming here, using instead recTypeId, for example.

3

Change this line objass.RecordType = recType.name; to this: objass.RecordTypeId = recType ;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.