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
QuickDEVQuickDEV 

command button invoking controller method

Hi,

 

Can I call a method present in the extension class onclick of a command button.

 

Or should that method be present in the standard or custom controller.

 

Thanks.

bob_buzzardbob_buzzard

You would need to set up an ActionFunction for the method you wish to call, and invoke that via JavaScript from the onclick event.

 

That said, a command button already takes an attribute of the method you want to invoke when the user presses it - can you not use that?

 

JPClarkJPClark

An example of Bob's second statement:

<apex:commandButton value="Search" action="{!Search}"/>

 

The value attribute is the text on the button and the action attribute is the method in the extension/controller that is to be executed.
QuickDEVQuickDEV

Thank you both for the replies.

 

what if the {!search}  method is an extension class but not either in standard or custom controller?

 

Thanks

JPClarkJPClark

An extension allows you to add methods to another controller. The methods in the extension are seen as if they are in the controller.

 

 

A controller extension is an Apex class that extends the functionality of a standard or custom controller. Use controller extensions when:
  • You want to leverage the built-in functionality of a standard controller but override one or more actions, such as edit, view, save, or delete.
  • You want to add new actions.
  • You want to build a Visualforce page that respects user permissions. Although a controller extension class executes in system mode, if a controller extension extends a standard controller, the logic from the standard controller does not execute in system mode. Instead, it executes in user mode, in which the profile-based permissions, field-level security, and sharing rules of the current user apply.