+ Start a Discussion
jdeveloperjdeveloper 

creating custom buttons for custom object

I have an object called book. I want to make a custom button for the book__c object called sell. If the book has been sold(book__c.book_Status__c == 'Sold') a message will display saying that the book has been sold. otherwise the button will take you to another visualforce page called book sell. does anyone have any suggestions.

Best Answer chosen by Admin (Salesforce Developers) 
KRKKRK

Hi Try this, this may help you


Select custom button Behavior as Executive Java Script and Content Source as OnClick JavaScript.



{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
var result = sforce.connection.query("Select Id From Book__c where Book_Status__c = 'Sold' and id = '{! Book__c.Id}' ");

var records = result.getArray("records");

if (records.length != 0){
alert("Your Error Message");
}
else
window.parent.location.href="{! urlFor('../apex/VisulaForcePageName')}"

All Answers

KRKKRK

Hi Try this, this may help you


Select custom button Behavior as Executive Java Script and Content Source as OnClick JavaScript.



{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
var result = sforce.connection.query("Select Id From Book__c where Book_Status__c = 'Sold' and id = '{! Book__c.Id}' ");

var records = result.getArray("records");

if (records.length != 0){
alert("Your Error Message");
}
else
window.parent.location.href="{! urlFor('../apex/VisulaForcePageName')}"

This was selected as the best answer
jdeveloperjdeveloper

thanks, that works just fine.

dmarkowitzdmarkowitz

Hi - can you please help me figure out the code to write in order to make a button to delete selected records from a list view in a custom object? The apps for that kind of thing aren't working for me so I want to simply create the new button to delete