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
Ankur DangwalAnkur Dangwal 

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;
 
 }
 
}
cvuyyurucvuyyuru
<apex:page controller="Example1">
	<apex:form >
		<div>
			<apex:commandButton value="Save" action="{!soo}"/>
					
					Name:<input type="Text"/><br/>
				<br/>
				<br/>
					A's Count = <apex:inputtext value="{!a}"/><br/>
				<br/>
				<br/>
					B's Count = <apex:inputtext value="{!b}"/><br/>
				<br/>
				<br/>
					C's Count = <apex:outputtext value="{!c}"/><br/>
				<br/>
		</div>
	</apex:form>
</apex:page>


public class Example1 {
	public string A{get;set;}
	public string B{get;set;}
	public string C{get;set;}

	public void soo(){
		C= string.valueOf(integer.valueof(A)+integer.valueof(B));
	}
 
}
shashi lad 4shashi lad 4

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
cvuyyurucvuyyuru
I agree that we don't need to have a string variable.

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.


 
Abdul RazzaqAbdul Razzaq

Hi Ankur, 

Could you make us aware about the error that you are getting?

Thank you.