I have a custom button created in the object called Account and this button execute javascript, content source is onclick javascript: Name of the button is Viewdetails and "ViewPage" here is a VF page. See below

{!REQUIRESCRIPT ("/soap/ajax/31.0/connection.js")} 

var selected = {!GETRECORDIDS($ObjectType.Account)} 
alert('Please Select Atleast One Account to View'); 
}else if(selected.length>1){ 
alert('Please Select Only One Account to View'); 

Now I'm trying to add this button in my existing VF page and let's call it " View".

I'm trying to add it as <apex:commandbutton but not sure how to do it. I know that I need to add something from the existing controller to call it in the View VF page, but I'm not sure how to do it well.

Any help will be much appreciated.

closed as off-topic by Oleksandr Berehovskyi, Basti, Raul, battery.cord, Gortonington Dec 21 '17 at 15:07

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on problems in code you've written must describe the specific problem and include valid code to reproduce it. For help writing short, self-contained syntactically-valid examples, see: SSCCE.org" – Oleksandr Berehovskyi, Basti, Raul, battery.cord, Gortonington
If this question can be reworded to fit the rules in the help center, please edit the question.


Following are few example you can try to add button visual force page

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

<apex:commandbutton  action="{!first}" value="First Group"></apex:commandbutton>

<apex:commandbutton action="{!previous}" value=" Previous Group" rendered="{!hasPrevious}"></apex:commandbutton>

 <apex:commandbutton action="{!next}"  value="Next Group"  rendered="{!hasNext}"></apex:commandbutton>

<apex:commandbutton action="{!last}" value="Last Group"></apex:commandbutton>
  • Already i added those buttons into page. Now i want to add onclick javascript List button using javascript in visualforce page – SFDC5578 Dec 21 '17 at 9:35

You can try like this

<apex:commandButton action="{!URLFOR($Action.Account.Edit, 'Your Account Id')}" id="editButton" value="Edit"/>


  • @Alexander Berehovskiy - I need to get the account records into table format using wrapper class and add custom buttons into same visualforce page. But, i get the wrapper class with account records. How to add custom buttons into page? – SFDC5578 Dec 21 '17 at 8:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.