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
mknobmknob 

Create Buttons with APEX instead of JavaScript (Force.com)

Hi.

I've buildet a simple button in the Account-Layout with Force.com. This button shows a message.

How i can create this with APEX in Eclipse-Force.com?

 

Code with JavaScript:

Account.objekt:

 <webLinks>
        <fullName>Hello</fullName>
        <availability>online</availability>
        <description>Say Hello</description>
        <displayType>button</displayType>
        <linkType>javascript</linkType>
        <masterLabel>Hello</masterLabel>
        <openType>onClickJavaScript</openType>
        <protected>false</protected>
        <url>alert (&quot;Hello {!User.Name}&quot; );</url>
    </webLinks>

 

Account-Account Layout .layout:

<customButtons>Hello</customButtons>
Message Edited by mknob on 10-01-2009 05:33 AM
paul-lmipaul-lmi

i'd love to see this as well.  i don't think you can do it at the moment.  what i did is write an apex class that holds all of the underlying methods i want to power with buttons, wrote a wrapper method that maps a URL parameter "action" to each method, and then finally a visualforce page that uses thet class as it's controller.  then, all i need to do to map a button to an apex method is make it a URL button to /apex/mypage?action=someaction .  it's not the greatest solution, but it's WAY better than using javascript and the API to do simple things like change a field on the click of a button.  this won't give you exactly what you're looking for (an alert box), but if you need to directly call custom logic in apex via a button on a native page layout, this will do it.

 

i'd rather have this be native though, for instance, having the ability to make the button directly call a method in an apex class, but i think there are limitations on the platform side preventing this, such as the fact that it'd be very difficult to carry data from the native page context to the custom apex logic we'd create.