Skip to content

Instantly share code, notes, and snippets.

@dangt85
Forked from tstachl/gist:2760221
Last active September 8, 2015 19:20
Show Gist options
  • Save dangt85/59433b49c73fe32584d3 to your computer and use it in GitHub Desktop.
Save dangt85/59433b49c73fe32584d3 to your computer and use it in GitHub Desktop.
Salesforce open Simple Dialog in custom button/link or on a visualforce page
// if you want to use it inside a visualforce page create a function around it
//function showFollowUp() {
// if you want to use it in a button make sure you require jQuery
// {!REQUIRESCRIPT("https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js")} // UNCOMMENT IF IN A BUTTON
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}
// get the dialog with your dialog name
var d = sfdcPage.dialogs['MyCoolDialog'], close;
if (!d) {
// if the dialog doesn't exist create one
d = sfdcPage.dialogs['MyCoolDialog'] = new SimpleDialog('MyCoolDialog'+Dialogs.getNextId(), false);
// set general information on your dialog and finally run the create function
d.setTitle('Change Status');
d.setWidth(600);
d.createDialog();
d.allowKeyboardEsc = true;
sforce.apex.execute("CaseTaskButtonController","getButtonContent",{page: "ButtonContent"},
{
onSuccess:function(result) {
console.log(result);
d.setContentInnerHTML(result);
},
onFailure: function(error) {
alert(error);
}
}
);
// we also need to make sure we have a close button on the dialog
if ($(d.dialog).find('#InlineEditDialogX').size() == 0) {
// if there is none we create it
close = $('<a id="InlineEditDialogX" title="Close" tabindex="0" href="javascript:void(0)" class="dialogClose">Close</a>');
// add some functionality to the close button - for the default ui we change the classname on mouseover/out
close.mouseover(function() {
this.className = 'dialogCloseOn';
}).mouseout(function() {
this.className = 'dialogClose';
}).click(function() {
// finally our on click handler which closes the dialog
d.hide();
});
// insert the new generated close button before the h2 tag so it'll show up on the top right corner
close.insertBefore($(d.dialog).find('.topLeft h2'));
}
}
// now it's time to show the new dialog
d.show();
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment