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

If statement help
Pretty new to this and hoping somebody can help...
I want to have a controller do some calculations for me.
for example, I want to return a weighting % based on age of the opportunity.
I have defined the age as such:
public integer getAge() { if(opp.isClosed == false)
return Date.valueof(opp.CreatedDate).daysBetween(date.today());
return Date.valueof(opp.CreatedDate).daysbetween(opp.CloseDate); }
However, I now want to build a decimal based on that, but cant seem to be able to access the Age value that I just created even thought it is public.
decimal weight = if(age<10) {.10;}else{.30;}
Does not work as it appears I cant use an if statment to define a variable. I get the error Expression cannot be a statement.
What is the proper way to do this?
decimal weight;
integer age = 5;
if(age<10) {
weight = .10; } else {
weight = .30;
}
system.debug(' ------- ' + weight );
Thanks, it still says that Age is not a variable.
Do I have to annotate it differently to call a variable defined in another function even if it is public?
try this...
integer age = getAge();