Is there a way I can test with an IF statement for a null object. Using an IF (obj==null) throws the error.

How can I account for these? With SOQL, I use a list and check the number. However, the return type for this map is an ID. I don't know how to check that. I'd also like to not use a list if possible.

 if (Schema.SObjectType.apm_applications__c.getRecordTypeInfosByName().get('NonExistentRecordType').getRecordTypeId()==null){
   system.debug('should be print ID ->' +

The problem is that you're not checking for null in time. There's no need to use try-catch (and you shouldn't, because they are incredibly expensive CPU-wise). The appropriate way would be to do this:

Map<String, RecordTypeInfo> apmRecordTypes = Schema.SObjectType.apm_applications__c.getRecordTypeInfosByName();
if(apmRecordTypes.containsKey('SomeRecordTypeName')) {
    Id recordTypeId = apmRecordTypes.get('SomeRecordTypeName').getRecordTypeId();
| improve this answer | |

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.