You need to sign in to do that
Don't have an account?
Matt Tindall
AggregateResult = NULL then show 0?
Hello,
I am trying to put an IF statement into my Class that determines if an Aggregate Result is NULL then place a 0 in its place.
Iv tried a few different ideas and just can't get it to work.
Public Integer getShowJanuarySales() { if (ShowJanuarySales > 0){ return ShowJanuarySales; } else { return 1; }
Iv got the following statement that works fine as long as a record exists and I know that it changes the value for me. But if I replace the "> 0" with "== null" I just get an error on my page saying it can't reference a null object.
Anyone got any ideas?
Matt
All Answers
Hi Matt,
I came across a similar issue once - have you tried the following:
if (ShowJanuarySales != NULL){
return ShowJanuarySales;
} else {
return 1;
}
Also, make sure you initialize the variable with a default value: ShowJanuarySales
ShowJanuarySales=0;
Hello Matt,
Aggregate result is always a number, so compare it with a number.
Thanks for the replies but its still not working.
I have created a micro concept to show what I am trying to do.
CLASS
VF PAGE
ERROR
If a record exists and even contains a 0 everything is fine. But sometime the record wont exist so I need to work out a solution.
Matt
Thats worked!!
Thanks,
Matt