You need to sign in to do that
Don't have an account?
Cris9931
Attempt do de-reference null object
I'm in a little bit of struggle here. Have an error in this class. I tried to debug log this error but I don't understand why only one user is having this problem. For the rest of the users this error does not occur. This is the error:
Why this error only occurs for only one user? I don't know why the code breaks. Any suggestions?
Visualforce Page: /apex/VisitReportPage caused by: System.NullPointerException: Attempt to de-reference a null object Class.VisitReportPageExtension.setIsFullReport: line 105, column 1 Class.VisitReportPageExtension.: line 65, column 1
This is my class:
public with sharing class VisitReportPageExtension { public List<SelectOption> PicklistValues { get; set; } public List<SelectOption> SecondPicklistValues { get; set; } public List<SelectOption> LastPicklistValues { get; set; } public Map<String, String> PicklistMap = new Map<String, String>(); Public List<String> selectedValues { get; set; } Public List<String> SecondselectedValues { get; set; } public List<String> LastSelectedValues { get; set; } public static final String DEFAULT_TASK_STATUS = 'New'; public static final String DEFAULT_TASK_PRIORITY = 'Normal'; public static final String EVENT_URL_PARAM = 'EventID'; public static final String RETURN_URL_PARAM = 'retUrl'; public static final String RECORD_TYPE_URL_PARAM = 'RecordType'; public static final String ACCOUNT_URL_PARAM = 'AccountId'; public static final String OPPORTUNITY_URL_PARAM = 'OpportunityId'; public static final String MEMO_REPORT_DEVELEOPER_NAME = 'Call_Memo'; private List<List<String>> contactFields; private Map<ID, Contact> contactsCache = new Map<ID, Contact>(); private Map<ID, User> userCache = new Map<ID, User>(); private List<Message> messages = new List<Message>(); private Map<Id, RecordType> mInteractionReportRecordTypes = null; private boolean isFullReport = true; private String retURLParam = null; public Boolean isNew { get; private set; } public Boolean showCreateContactPopup { get; set; } public List<ActionItemWrapper> actionItems { get; set; } public List<CustomerParticipantWrapper> customerParticipants { get; set; } public List<CustomerParticipantWrapper> internalParticipants { get; set; } public Contact contactHandler { get; set; } public Visit_Report__c record { get; set; } /** * Constructor creates instance of class. Loads Interaction * report and related records. * @param stdCtr Standard controller. */ public VisitReportPageExtension(ApexPages.StandardController stdCtr) { customerParticipants = new List<CustomerParticipantWrapper>(); internalParticipants = new List<CustomerParticipantWrapper>(); record = (Visit_Report__c) stdCtr.getRecord(); isNew = (stdCtr.getId() == null); mInteractionReportRecordTypes = RecordTypeService.getRecordTypesForObject('Visit_Report__c'); loadParams(); loadInteractionRecord(); clearContactHandler(); closeCreateContactPopup(); setIsFullReport(record.RecordTypeId); selectedValues = new List<String>(); SecondselectedValues = new List<String>(); LastSelectedValues = new List<String>(); PicklistValues = new List<SelectOption>(); SecondPicklistValues = new List<SelectOption>(); LastPicklistValues = new List<SelectOption>(); List<Schema.PicklistEntry> FieldPicklistvalues = Visit_Report__c.Innovation_presented_to_customer__c.getDescribe().getPicklistValues(); for (Schema.PicklistEntry FieldPicklistvaluesfor : FieldPicklistvalues) { PicklistValues.add(new SelectOption(FieldPicklistvaluesfor.getValue(), FieldPicklistvaluesfor.getLabel())); PicklistMap.put(FieldPicklistvaluesfor.getvalue(), FieldPicklistvaluesfor.getLabel()); } } private void loadParams() { Map<String, String> mGetParams = ApexPages.currentPage().getParameters(); record.EventID__c = mGetParams.get(EVENT_URL_PARAM); retURLParam = ApexPages.currentPage().getParameters().get(RETURN_URL_PARAM); //TODO get rec type if (record.RecordTypeId == null) { if (mGetParams.containsKey(RECORD_TYPE_URL_PARAM)) { record.RecordTypeId = mGetParams.get(RECORD_TYPE_URL_PARAM); } } if (mGetParams.containsKey(ACCOUNT_URL_PARAM)) { record.Account_Name__c = mGetParams.get(ACCOUNT_URL_PARAM); } } private void setIsFullReport(Id recordTypeId) { isFullReport = (mInteractionReportRecordTypes.get(recordTypeId).DeveloperName != MEMO_REPORT_DEVELEOPER_NAME); } public boolean getIsFullReport() { return isFullReport; } }
Why this error only occurs for only one user? I don't know why the code breaks. Any suggestions?
private void setIsFullReport(Id recordTypeId) {
if(mInteractionReportRecordTypes.containskey(recordTypeId))
isFullReport = (mInteractionReportRecordTypes.get(recordTypeId).DeveloperName != MEMO_REPORT_DEVELEOPER_NAME);
else
isFullReport = null;
}
All Answers
That your map cannot be printed inline, that's not an error but a warning.
Are you able to run this from anonymous window? Since the current user in anonymous window is always Sys Admin, we will be sure that running as admin will work, just to exclude the that possibility. If so, then please paste some error logs here
the logs from this user are here.... with the error....
Continue...
yea.. you are right...
This is the continue...
and last part....
private void setIsFullReport(Id recordTypeId) {
if(mInteractionReportRecordTypes.containskey(recordTypeId))
isFullReport = (mInteractionReportRecordTypes.get(recordTypeId).DeveloperName != MEMO_REPORT_DEVELEOPER_NAME);
else
isFullReport = null;
}
if a key is not present in Map and without checking containskey if code directly try to get the value from map it will give null pointer exception
so it's awlays good pratice to use map.containskey before you do map.get
Also map key is case sensative so check containskey always help before doing get from Map
It will be greate if you can you mark asnwer as sovled , i will help keep community clean