You need to sign in to do that
Don't have an account?

InputText integer "0" instead of "null"
SF developers,
I need an advice. I have visual page with inputText
I found a page that describes this problem https://salesforce.stackexchange.com/questions/64339/apex-inputtext-bound-to-integer-takes-0-instead-of-null
I try to create string setter
But, now, i have error message "
Error: Read only property 'inputIntegerCtrl.intValue'"
Does anyone know how to solve this problem?
I need an advice. I have visual page with inputText
<apex:page controller="inputIntegerCtrl"> <apex:form > <apex:pageBlock > <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!saveValue}" reRender="bs"/> </apex:pageBlockButtons> <apex:pageBlockSection columns="1" id="bs"> <apex:inputText label="value" value="{!intValue}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
public class inputIntegerCtrl { public Integer intValue {get;set;} public void saveValue() { } }When I try to delete variable value and press button "Save", value integer variable is becoming "0" instead of "null"
I found a page that describes this problem https://salesforce.stackexchange.com/questions/64339/apex-inputtext-bound-to-integer-takes-0-instead-of-null
I try to create string setter
public class inputIntegerCtrl { public Integer intValue; public String getIntValue() { return String.valueOf(intValue); } public void setIntValue(string intValue) { if (intValue != null) this.intValue = Integer.valueOf(intValue); } public void saveValue() { } }
But, now, i have error message "
Error: Read only property 'inputIntegerCtrl.intValue'"
Does anyone know how to solve this problem?
That was just an example to help you understand how you can use it. As I said, you need to use ternary operator to determine the text field filled with an interger value.
public String str {get;set;}
Integer value = !String.isBlank(str) ? Integer.valueOf(str) : null;
That's how you can get null in the 'Value' variable.
Do let me know if I am still missing on anything, would happy to help you.
All Answers
This behaviour is implicit on the platform. You can user ternary operator to determine if the field is blank, please see below example for a reference - NOTE: Longs have a minimum value of -2^63 and a maximum value of 2^63-1
Happy Coding!! Do reply on the same post if you any follow up questions for the same thread.
Thanks for your answer, but I need field integer :-(
String type intValue, work wery well, but interger type has problem with "null"
That was just an example to help you understand how you can use it. As I said, you need to use ternary operator to determine the text field filled with an interger value.
public String str {get;set;}
Integer value = !String.isBlank(str) ? Integer.valueOf(str) : null;
That's how you can get null in the 'Value' variable.
Do let me know if I am still missing on anything, would happy to help you.
DevADS, thank you for help me.
Happy Coding!!