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
AbAb 

Display sucess message to user after a click on custom button

Hello,

I have a Custom Button on a Page, which has
behaviour:Execute JavaScript
Content Source: Onclick JavaScript

Everything works perfect.

After button is clicked, I want to show a success message to user. Saying "Sucess".
It can be a popup or a hml text on page.

 
Best Answer chosen by Ab
NagaNaga (Salesforce Developers) 
Hi Sandrine,


How about this(http://www.screencast.com/t/MmawCbPc) ? If you like that then here you go:

1. Go to Setup | Customize | <Standard Object Name> | Buttons, Links & Actions and then Click 'New Button or Link' or if it is a Custom Object then go to Setup | Create | Objects and then click on the Custom Object name. Scroll down to find the section 'Buttons, Links, and Actions' and then click  'New Button or Link'.
2. Give it the Label: <A Valid Name>.
3. Display Type: Detail Page Button.
4. Behavior: Execute JavaScript.
5. Content Source: OnClick JavaScript.

Here is the JS:

{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js')}
{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js')}
try{
  jQuery(function() {
    /*Append the jQuery CSS CDN Link to the Head tag.*/
    jQuery('head').append('<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/start/jquery-ui.css" type="text/css" />');
    
    /*Create the HTML(DIV Tag) for the Dialog.*/
    var html = 
      '<div id="dialog" title="Go Home"><p>Do you want to go to the Home tab ?</p></div>';
    
    /*Check if the Dialog(DIV Tag) already exists if not then Append the same to the Body tag.*/
    if(!jQuery('[id=dialog]').size()){
      jQuery('body').append(html);
    }    

    /*Open the jQuery Dialog.*/ 
    jQuery( "#dialog" ).dialog({
      autoOpen: true,
      modal: true,
      show: {
        effect: "bounce",
        duration: 1000
      },
      hide: {
        effect: "bounce",
        duration: 1000
      },
      buttons: {
        "Continue": function() {
          location.replace('/home/home.jsp');
          jQuery( this ).dialog( "close" );
        },
        Cancel: function() {
          jQuery( this ).dialog( "close" );
        }
      }
    });
  }); 
}
catch(e){
alert('An Error has Occured. Error: ' + e);
}

Save the same!

7. Now, just open any Record, click Edit Layout at top-right..
9. From the Page Host, select Buttons list and drag the new button onto the Page Layout.
10. Save and you are done!


Please let me know if this helps

Best Regards
Naga Kiran

All Answers

NagaNaga (Salesforce Developers) 
Hi Sandrine,


How about this(http://www.screencast.com/t/MmawCbPc) ? If you like that then here you go:

1. Go to Setup | Customize | <Standard Object Name> | Buttons, Links & Actions and then Click 'New Button or Link' or if it is a Custom Object then go to Setup | Create | Objects and then click on the Custom Object name. Scroll down to find the section 'Buttons, Links, and Actions' and then click  'New Button or Link'.
2. Give it the Label: <A Valid Name>.
3. Display Type: Detail Page Button.
4. Behavior: Execute JavaScript.
5. Content Source: OnClick JavaScript.

Here is the JS:

{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js')}
{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js')}
try{
  jQuery(function() {
    /*Append the jQuery CSS CDN Link to the Head tag.*/
    jQuery('head').append('<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/start/jquery-ui.css" type="text/css" />');
    
    /*Create the HTML(DIV Tag) for the Dialog.*/
    var html = 
      '<div id="dialog" title="Go Home"><p>Do you want to go to the Home tab ?</p></div>';
    
    /*Check if the Dialog(DIV Tag) already exists if not then Append the same to the Body tag.*/
    if(!jQuery('[id=dialog]').size()){
      jQuery('body').append(html);
    }    

    /*Open the jQuery Dialog.*/ 
    jQuery( "#dialog" ).dialog({
      autoOpen: true,
      modal: true,
      show: {
        effect: "bounce",
        duration: 1000
      },
      hide: {
        effect: "bounce",
        duration: 1000
      },
      buttons: {
        "Continue": function() {
          location.replace('/home/home.jsp');
          jQuery( this ).dialog( "close" );
        },
        Cancel: function() {
          jQuery( this ).dialog( "close" );
        }
      }
    });
  }); 
}
catch(e){
alert('An Error has Occured. Error: ' + e);
}

Save the same!

7. Now, just open any Record, click Edit Layout at top-right..
9. From the Page Host, select Buttons list and drag the new button onto the Page Layout.
10. Save and you are done!


Please let me know if this helps

Best Regards
Naga Kiran
This was selected as the best answer
Hemanth DesirajuHemanth Desiraju
I am also facing the same issue. this code works. thanks