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
manojjain4328manojjain4328 

How can i pass optional/default parameter in apex mathod?

Hi all,

 

I want to pass optional/default parameter in apex method,same as java.

But it throws error.

 

Is there any special way to pass optional/default parameter in apex method?

 

Please help me.

 

Regards,

Manoj Jain 

 
03-19-2010 04:21 PM

Best Answer chosen by Admin (Salesforce Developers) 
Novo_ArtisNovo_Artis

First of all... PLEASE SEARCH BEFORE POSTING (I found the answer within two seconds of doing so)

 

You can't using optional and default values in functions but you can use overloading.

 

eg.

 

 

public void foo(String xyz) { system.debug(xyz); } public void foo() { foo('FOOBAR'); } foo();

 

 

The above will print FOOBAR to the debug log.

 

If you still dont understand, google it.

All Answers

EnthEnth
You need to supply an example of the code you have an issue with. You can always check in your method if the value passed is null and set your default to a class constant value.
Novo_ArtisNovo_Artis

First of all... PLEASE SEARCH BEFORE POSTING (I found the answer within two seconds of doing so)

 

You can't using optional and default values in functions but you can use overloading.

 

eg.

 

 

public void foo(String xyz) { system.debug(xyz); } public void foo() { foo('FOOBAR'); } foo();

 

 

The above will print FOOBAR to the debug log.

 

If you still dont understand, google it.

This was selected as the best answer