0

I want to assign Recordtype Developer Name for the new case that I am creating through Batch Apex.

my code line is as below.

RecordType.DeveloperName = Policy_Line_Item,

I am getting compile time error.

Invalid field initializer: RecordType.DeveloperName

0

You cannot set the related fields in a single call unless you are using external Id fields and structure it differently.

You need to populate the RecordTypeId field with the value of the desired RecordType's Id

Keep in mind the describe getRecordTypeInfosByName returns Name NOT Developer Name

So you can do something like this and in this case you would need a query:

Map<String,Id> devToId = New Map<String,Id>();

for(RecordType rt :[Select Id, DeveloperName from RecordType Where sObjectType = 'Opportunity' and isActive = true]){

      devToId.put(rt.DeveloperName,rt.Id);

}

Make sure that you cache it or use a lazy load static method or similar technique so it can me used in multiple places without requerying.

  • Or he can use the getRecordTypeInfosByDeveloperName method from the class DescribeSObjectResult Schema.getGlobalDescribe().get(objectName).getDescribe().getRecordTypeInfosByDeveloperName().get(developername).getRecordTypeId(); This method will return the Id using developername. For more Infos: developer.salesforce.com/docs/atlas.en-us.apexcode.meta/… – Mo Hamada Feb 8 at 9:19
  • @MoHamada now you can yes. It did not exist when this question was asked – Eric Feb 9 at 6:15
  • Sorry I didn't see the date of the post. – Mo Hamada Feb 11 at 10:11

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.