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

issue with apex code
Hi,
I have written a vf page with controller Example1 to get sum of input field A, B in the third field C. however I am getting error while click on save. code is mentioned below, please help.
<apex:page controller="Example1" >
<apex:form >
<div>
<apex:commandButton value="Save" action="{!soo}"/>
Name:<input type="Text"/><br/>
<br/>
<br/>
A's Count = <input type="Integer"/><br/>
<br/>
<br/>
B's Count = <input type="Integer"/><br/>
<br/>
<br/>
C's Count = <Output type="Integer"/><br/>
<br/>
</div>
</apex:form>
</apex:page>
public class Example1 {
public integer A{get;set;}
public integer B{get;set;}
public integer C{get;set;}
public integer soo(){
C= A+B;
return C;
}
}
I have written a vf page with controller Example1 to get sum of input field A, B in the third field C. however I am getting error while click on save. code is mentioned below, please help.
<apex:page controller="Example1" >
<apex:form >
<div>
<apex:commandButton value="Save" action="{!soo}"/>
Name:<input type="Text"/><br/>
<br/>
<br/>
A's Count = <input type="Integer"/><br/>
<br/>
<br/>
B's Count = <input type="Integer"/><br/>
<br/>
<br/>
C's Count = <Output type="Integer"/><br/>
<br/>
</div>
</apex:form>
</apex:page>
public class Example1 {
public integer A{get;set;}
public integer B{get;set;}
public integer C{get;set;}
public integer soo(){
C= A+B;
return C;
}
}
I don't think we need to convert into String. Also in above example it will give an error for soo() because its not pagereference method.
Simple example :
----------- page -----------
<apex:page controller="sumController" >
<apex:form >
value of a = <apex:inputText value="{!a}"/>
value of b = <apex:inputText value="{!b}"/>
<apex:commandButton value="add" action="{!doAdd}" />
total = <apex:outputText value="{!c}"/>
</apex:form>
</apex:page>
------------ controller----------
public class sumController {
public Integer a { get; set; }
public Integer b { get; set; }
public Integer c {get;set;}
public pageReference doAdd(){
c = a + b;
return null;
}
}
Please mark solved if it answered your question.
Thanks
Shashi
By default, when we create using development mode, Salesforce created varaibles of string type and I didn't change it.
It will not give an error for soo() method. Pagereference is not mandatory for methods.
Hi Ankur,
Could you make us aware about the error that you are getting?
Thank you.