You need to sign in to do that
Don't have an account?
Developer IronSource
getter method in visualforce throwing an error
Hi,
I have a visualforce which has some buttons.
The buttons are rendered according to the getter methods in the controller.
For Example:
The VF:
The problem is that sometimes I get a null pointer exception inside the method. Probably the obj variable is null but it's not null for certain because the whole page is surrounded by it.
I tried putting a try and catch but I can't do nothing inside the catch .. I can't do dml functions inside a getter as well as calling a future method, So I don't know how to monitor it.
It should be noted that the null pointer exception is not happaning all the time.
The only thing I can think about is that it's happaing due to poor network connection which causing the obj to be null.
Any idea how to monitor or solving that problem ?
Thanks.
I have a visualforce which has some buttons.
The buttons are rendered according to the getter methods in the controller.
For Example:
The VF:
<apex:commandbutton rendered="{!EditButtonVisibility}" styleclass="slds-button slds-button--neutral" action="{!changeEditMode}" status="processStatus" value="Edit" />The controller:
public Boolean getEditButtonVisibility() { if (obj.Approval_Status__c != null && obj.Approval_Status__c.equalsIgnoreCase('Pending')){ return true; } return false; }
The problem is that sometimes I get a null pointer exception inside the method. Probably the obj variable is null but it's not null for certain because the whole page is surrounded by it.
I tried putting a try and catch but I can't do nothing inside the catch .. I can't do dml functions inside a getter as well as calling a future method, So I don't know how to monitor it.
It should be noted that the null pointer exception is not happaning all the time.
The only thing I can think about is that it's happaing due to poor network connection which causing the obj to be null.
Any idea how to monitor or solving that problem ?
Thanks.
As for monitoring, we've done some stuff with google analytics and / or loggly to dump data on actions to them. You could wirte a javascript method that fires on page load and dumps the contents of your obj object as well as other data if the obj object is null. Then just update your method to have a null check for obj so that your users don't get the error message.
The vf+controller are very long so it's impossible to put it here.
Notice that it's a getter method which happans on page load (it's responsible for rendering the button), that's why I think it might be connectivity issue.
About Google Analytics / Loggle - do you have an example of how to implement it ?
[1] https://developers.google.com/analytics/devguides/collection/analyticsjs/exceptions