You need to sign in to do that
Don't have an account?
AVINASH UPADHYA
Hi All,
I am trying to build a Simpale calculator in different way. I have created a custome object Calculator__C having 3 fields Var1, Var2, Result.
Bellow is the controller for same but its not working. Please suggest me what needs be modified in bellow code.
public class CalculatorController {
public Calculator__C Calc {get; set;}
Public void Add(){
Calc.Result__c = Calc.Var1__c + Calc.Var2__c;
}
Public void Sub(){
Calc.Result__c = Calc.Var1__c - Calc.Var2__c;
}
Public void Div(){
Calc.Result__c = Calc.Var1__c / Calc.Var2__c;
}
}
Simple Calculator!
Hi All,
I am trying to build a Simpale calculator in different way. I have created a custome object Calculator__C having 3 fields Var1, Var2, Result.
Bellow is the controller for same but its not working. Please suggest me what needs be modified in bellow code.
public class CalculatorController {
public Calculator__C Calc {get; set;}
Public void Add(){
Calc.Result__c = Calc.Var1__c + Calc.Var2__c;
}
Public void Sub(){
Calc.Result__c = Calc.Var1__c - Calc.Var2__c;
}
Public void Div(){
Calc.Result__c = Calc.Var1__c / Calc.Var2__c;
}
}
You will also need to do a re-render [1] of your result if you want to see that it changed.
[1] https://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_actionRegion.htm
All Answers
NOTE: Please use the "Add a code sample" button (icon <>) to help increase readability
I am getting a error as below
System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!Add}' in component <apex:commandButton> in page vfcalculator: Class.CalculatorController.Add: line 11, column 1
Class.CalculatorController.Add: line 11, column 1
You will also need to do a re-render [1] of your result if you want to see that it changed.
[1] https://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_actionRegion.htm
If you want to develop a Simple calculator using Aura then the below link will be helpful to you.
https://viewonreview.com/salesforce-lightning-tutorial-for-beginners/