0
   public final static string SIR_SYSTEMS_RECORD = 'SIR_Form_Systems';

public static boolean checkRecordType(Sales_Toolkit__c[] newQuote){
        Map<Id,Schema.RecordTypeInfo> rtMap = Account.sobjectType.getDescribe().getRecordTypeInfosById();
        Boolean rTypeCheck = TRUE;
            for(Sales_Toolkit__c st : newQuote){
        string recordTypeName = rtMap.get(st.RecordTypeId).getDeveloperName();
        if(recordTypeName == SIR_SYSTEMS_RECORD)
        rTypeCheck = FALSE;
            }
            return rTypeCheck; 
    }

now from what i know rtMap.get(st.RecordTypeId).getName() would get the label name, but that's more than useless and we have standards that label names are not allowed to be referenced in code only API names. Anyhoo when i switched to getDeveloperName() is borks up and gives a 'attempt to de-reference a null object'.

Also the parameter being passed always has a record type, it's the after update trigger.new

1

You're describing Account, but iterating over Sales_Toolkit__c records. This is the main problem. In addition, a record can have a null record type, you should be prepared for that. Finally, you only need to get the name once, so use getRecordTypeInfosByDeveloperName instead.

public final static Id SIR_SYSTEMS_RECORDTYPE_ID = 
    sobjectType.Sales_Toolkit__c
   .getRecordTypeInfosByDeveloperName()
   .get('SIR_Form_Systems').getRecordTypeId();

public static Boolean checkRecordType(Sales_Toolkit__c[] records) {
    for(Sales_Toolkit__c record: records) {
        if(record.RecordTypeId == SIR_SYSTEMS_RECORDTYPE_ID) {
            return false;
        }
    }
    return true;
}
1

You're using getDescribe on the Account object, while you should run it on the Sales_Toolkit__c object. The returned map will thus contain Account record type IDs, so it's normal it returns null when you try to look for a Sales Toolkit record type ID

2
  • 1
    I would even say "expected" instead of "normal"; the map literally will not contain the correct record types by Id. – sfdcfox May 14 at 18:04
  • True! Hehe seems like you were a few seconds early with a more detailed reply. – nicolas May 14 at 18:07

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.