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
michael_mcmahonmichael_mcmahon 

if statement controller help, simple

A custom object, Data with three custom fields, Baseline, Change, and Proj

 

I'm trying to write:   If (change = blank, proj = baseline , else proj  = baseline + (baseline * change)

 

Here's my code but it's not working and I could use some help correcting it:

public class ROI_Calc{
    public static Integer calculateROI (data__c.lifetime_orders_projected__c v) {
        if (lifetime_order_value_change_proj__c == '') {
            v = lifetime_order_value_baseline__c; }
           {v = lifetime_order_value_baseline__c * lifetime_order_value_change_proj__c + lifetime_order_value_baseline__c;
           } 
    }
}

 

Best Answer chosen by Admin (Salesforce Developers) 
Prafull G.Prafull G.

Hi Michael,

 

Try the following:

 

public class ROI_Calc{
    public static Integer calculateROI (data__c v) {
        if (v.lifetime_order_value_change_proj__c == '') {
            v.lifetime_orders_projected__c = v.lifetime_order_value_baseline__c; 
	}
	else{
		lifetime_orders_projected__c = lifetime_order_value_baseline__c  +  (lifetime_order_value_change_proj__c *lifetime_order_value_baseline__c);
        } 
    }
}

 Please note that, the parameter v is of type object Data__c. In addition, i have added the else as well.

All Answers

Prafull G.Prafull G.

Hi Michael,

 

Try the following:

 

public class ROI_Calc{
    public static Integer calculateROI (data__c v) {
        if (v.lifetime_order_value_change_proj__c == '') {
            v.lifetime_orders_projected__c = v.lifetime_order_value_baseline__c; 
	}
	else{
		lifetime_orders_projected__c = lifetime_order_value_baseline__c  +  (lifetime_order_value_change_proj__c *lifetime_order_value_baseline__c);
        } 
    }
}

 Please note that, the parameter v is of type object Data__c. In addition, i have added the else as well.

This was selected as the best answer
michael_mcmahonmichael_mcmahon

Ah, thank you very much.  

 

I have to build at least ten of these, so it ocurred to me to make it simpler to change out the formulae I could use something like 

let base = v.lifetime_value__c

 but I can't figure out how to do this in Force.com.  I swear I have looked for at least an hour, and have tried all kinds of variations including declaring an Integer which also didn't work.  Any chance you could help me out with one more line of code?

 

thanks a lot,  Michael