function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SivaGSivaG 

NullPointer Exception

Hi,

I am getting a null pointer exception in controller class for the below line.I assume opportunityQuoteRecordType is having a null value in some scenario. There are 4 options on VF page to select opportunityQuoteRecordType. opportunityQuoteRecordType is defaulted to some value in constructor and its selected in VF page when loads.

How to fix this issue?

queryString += ' and QQ_Plan_Pricing_Mthd_dim__c = \'' + string.escapeSingleQuotes(opportunityQuoteRecordType) + '\'';

Thanks
Kumar
 
Best Answer chosen by SivaG
KaranrajKaranraj
Have null check before the condition like this below
If(opportunityQuoteRecordType ! = null)
queryString += ' and QQ_Plan_Pricing_Mthd_dim__c = \'' + string.escapeSingleQuotes(opportunityQuoteRecordType) + '\'';
Check the debug log what value is assigned before this condition for that variable, by this you can eaily track and solve your problem.

All Answers

KaranrajKaranraj
Have null check before the condition like this below
If(opportunityQuoteRecordType ! = null)
queryString += ' and QQ_Plan_Pricing_Mthd_dim__c = \'' + string.escapeSingleQuotes(opportunityQuoteRecordType) + '\'';
Check the debug log what value is assigned before this condition for that variable, by this you can eaily track and solve your problem.
This was selected as the best answer
SivaGSivaG
Hi Karan,

Actually it happened in production. I am not able  to recreate the scenario in dev sandbox. I checked the debug log in test and don't see any exception.

As mentioned I can add not NULL check but that would not serve the purpose. If it returns null then we will miss 'and QQ_Plan_Pricing_Mthd_dim__c = Opprectype' condition in query. I am thinking to put this code in try/catch block. And in catch block I will have default record type. What say?

Thanks
Kumar
 
KaranrajKaranraj
Yes thats better idea, but always try replicate the issue to identify the exact reason before making any change in your code. Don't have an assumption, which should not lead to some other problem.