Just want to confirm if Salesforce Apex don’t support parameters like Java and other languages?
For example:
It’s a simple function with parameters in Java. And, Salesforce Apex DO NOT support such kind of syntax. Am I right?
public int mult(int x, int y)
{
return x * y;
}
Salesforce can pass parameters from Javascript or Visualforce Page to Apex, however, I never see parameters within function/class in Apex language so just want to make sure it. If Salesforce have function and parameters then we can write apex code more with efficient structure.
Added by 2012-12-18 ===========================
Thanks Gerard Sexton, it works.
Sample codes:
public class MyClass {
public integer mult(integer x, integer y)
{
return x * y;
}
}
MyClass m = new MyClass();
System.debug(m.mult(3,4));
The result is 12.
Apex does support method parameters.
Here are the docs for defining a class method.
These methods can be accessed and used ONLY within APEX. To use data passed in from a Visualforce page, please see these docs for an example.
In the visualforce example they use
searchTextas a class instance property, but in standard programming languages we would pass it in as a method parameter.