I have to trigger some actions for records of a certain record type. When doing this via trigger and getting the record type value of the record in the debug statement I am receiving NULL, which is why it is not going inside my IF Statement. What is the mistake I am making ??

Trigger.newMap.get(FARecId).Recordtype.DeveloperName is coming as NULL



Trigger FATrigger on Financial_Account__c (After Update) 
    if(trigger.isAfter && trigger.isUpdate)
        For(Id FARecId : Trigger.newMap.keySet())
            System.debug('----Record type name is' + Trigger.newMap.get(FARecId).Recordtype.DeveloperName);

            IF(Trigger.newMap.get(FARecId).Recordtype.DeveloperName == 'Retail')
                System.debug('----Inside IF Statement 1----');

Only the object's base fields are loaded from the database in triggers. To get related objects, you need to either query for them or use describe calls. In this specific case, you would use a describe call:

Map<Id, RecordTypeInfo> rtinfos = Financial_Account__c.getDescribe().getRecordTypeInfosById();
for(Financial_Account__c record: Trigger.new) {
    String rtName = '-- Master --';
    if(rtinfos.containsKey(record.RecordTypeId)) {
        rtName = rtinfos.get(record.RecordTypeId).getName();
  • I had to add "sObjectType" => "Financial_Account__c.sObjectType.getDescribe()..."
    – Johannes
    Jun 21 '19 at 15:55

The answer by sfdcfox solves the problem.

I have other approach which involves creating a formula field on your Financial Account record which fetches record type name.

You can access that field in your trigger, it makes code simpler but you sacrifice a formula field.

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.