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
Hank RyanHank Ryan 

How do I add a custom button to a VisualForce pageBlockButtons section?

I have a custom button on one of my custom objects called with an API name of "DeleteX".  I want to include this button in the button bar of my visual force page right next to the edit button.  But when I say "action='{!DeleteX}'" in the commandButton component it doesn't work.  Is what I'm trying to do possible and if so what's the syntax?

 

Thanks in advance. Here's my page as it currently exists.

 

 

<apex:page standardController="Web_Integration__c" showHeader="true" tabStyle="opportunity" title="Web Integration: {!Web_Integration__c.Name}"> <apex:form > <apex:pageBlock title="Web Integration Detail"> <apex:pageBlockButtons > <apex:commandButton action="{!edit}" value="Edit"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>

 

 - Hank

 

Best Answer chosen by Admin (Salesforce Developers) 
jeffdonthemicjeffdonthemic

Ryan,

 

You can add a button like this:

 

 

<apex:page standardController="Web_Integration__c" showHeader="true" tabStyle="opportunity" title="Web Integration: {!Web_Integration__c.Name}">
<apex:form >
<apex:pageBlock title="Web Integration Detail">
<apex:pageBlockButtons >
<apex:commandButton action="{!edit}" value="Edit"/>
<apex:commandButton action="{!deleteMe}" value="Delete Me"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>

 

In your controller you will need something like:

 

 

public PageReference deleteMe() { // perform your business logic here return null; }

 


Good luck

 

Jeff Douglas

Informa Plc

http://blog.jeffdouglas.com

 

 

 

All Answers

jeffdonthemicjeffdonthemic

Ryan,

 

You can add a button like this:

 

 

<apex:page standardController="Web_Integration__c" showHeader="true" tabStyle="opportunity" title="Web Integration: {!Web_Integration__c.Name}">
<apex:form >
<apex:pageBlock title="Web Integration Detail">
<apex:pageBlockButtons >
<apex:commandButton action="{!edit}" value="Edit"/>
<apex:commandButton action="{!deleteMe}" value="Delete Me"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>

 

In your controller you will need something like:

 

 

public PageReference deleteMe() { // perform your business logic here return null; }

 


Good luck

 

Jeff Douglas

Informa Plc

http://blog.jeffdouglas.com

 

 

 

This was selected as the best answer
Hank RyanHank Ryan

Oh right... the controller. I guess what I was asking was whether actions for custom buttons are automatically created in the standard controller code.  Is the answer that "no" then?

 

Thanks so much for your reply, by the way.

 

 - Hank

jbardetjbardet

Hey all,

 

I'm trying to do something similar, calling a custom button in VF. I've been piecing together a solution for myself using this thread and other similar ones, but I still have a loose end or two.

 

If anyone is generous or interested in helping me out, I'd really appreciate it.

 

http://boards.developerforce.com/t5/Visualforce-Development/Custom-Button-on-oppty-standard-layout-works-but-not-in-VF-page/td-p/671226

 

If the solution is more involved, I'm happy to pay for your time.

 

Regards,

jeremy