Call a apex method from a custom button

apex-codesalesforce

i want to call a apex method from a custom Button

I realise we can achieve this 2 ways

  1. Calling a VF page which in turn calls the method on the page attribute
    <apex:page standardController="Opportunity" extensions="oppExt" action="{!changeStatus}"/>

  2. use javascript to call the webservices method

The question i have is on the which is best practice to it for this scenario.

Thanks

Best Answer

It depends on your use case. The API supports both Controllers and Extensions and JavaScript Remoting or JavaScript with Web Services. These methods are all based on defined standards; it's really up to the developer or development team.

JavaScript is more suited for interfaces that display smaller amounts of data, but it is generally more user friendly.

I'd recommend the AJAX Toolkit over JavaScript Remoting for this task. It's better suited for single field updates; JavaScript Remoting is better suited for accessing Apex methods through JavaScript. However, the same result can be accomplished with either.

Related Topic