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
sapnajaamdarsapnajaamdar 

pop up message on click of save on std page

Hi All,

 

We have a requirement to display user confirmation pop up  on-click of std ‘Save’ button on opportunity page layout.

We have achieved it through JS on home page component. It works neatly for the normal edit page but does not work well on the inline edit page.

The problem is that although the pop up message gets displayed, the "SAVE' thereafter does not happen. Appreciate any help on this.

Below is the code snippet for inline edit page:

 

function overrideTheSavebtn(){

var URL = document.location.href;

if(URL.indexOf('006') > 0){

var probab = document.getElementById('opp12');

if( probab.value!='90')

{

document.getElementsByName('inlineEditSave')[0].onclick = function(){

var choice = confirm('All orders will be deleted if you change the probability to less than 90. Do you want to continue?'); return choice;};}

}}

/* add a method onload */

var oldonload = window.onload;

if (typeof window.onload != 'function') {

window.onload = oldonload; }

else { window.onload = function() {

if (oldonload) { oldonload();}

overrideTheSavebtn();}}

</script>

 

 

Regards,

Sapna

Best Answer chosen by Admin (Salesforce Developers) 
sapnajaamdarsapnajaamdar

I got it working for the inline edit page as well!

Here is the update code:

 

document.getElementsByName('inlineEditSave')[0].onclick = function(){
 if(accstatus.value=='Locked'){
   var userchoice =confirm('Are you sure you want to lock the Account?');
   if(userchoice){sfdcPage.save(); return userchoice;}
   else{sfdcPage.revert(); return userchoice;}
 }
 else{sfdcPage.save(); return userchoice;}
};

 

 

All Answers

*werewolf**werewolf*

There's not really any good way to override the Save button.  Even the sidebar component is a bit of a hack, I'm surprised that it works because sidebar components are usually served from a different domain than the main page.  You seem to be keying on onload, but inline edit doesn't really reload the page either.

 

Are you trying to pop up some kind of confirmation message or something?

sapnajaamdarsapnajaamdar

Yes, we're trying to pop up a confirmation message.

The problem we are really facing is that the pop up message does display on the inline Save button as well but the record does not get saved.

This is the Onclick Function we've added:

 

document.getElementsByName('inlineEditSave')[0].onclick = function(){if(accstatus.value=='Locked'){var userchoice = confirm('Are you sure you want to lock this Account?');return userchoice;}};

 

 

If you see the page source, You will find that there is a onClick function defined on that button:

 

<input value=" Save "  class="btn" title="Save" style="display: none;" name="inlineEditSave" onclick="sfdcPage.save();" type="button" />

 

 

Im not much of a javascript person but i have a feeling it has got something to do with the way the below code is written:

 

 

add a method onload */ var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = oldonload; } else { window.onload = function() { if (oldonload) { oldonload();}overrideTheSavebtn ();}}

 

 

 

 

*werewolf**werewolf*

Yeah you've got some seriously messed up code there.  First of all, you are overriding the onclick action of the save button with your confirmation message; that's why it never saves, because it never gets called.  Only your override ever gets called.  Then you're appending your function to the onload of the window, which is not at all where you want your override.

 

Ironically it's not that far off from what you want to do.  See what you're doing with the onload?  If you applied that instead to document.getElementsByName('inlineEditSave')[0].onclick then it might actually work.

 

That said, this is a huge hack.  I wouldn't be surprised if it randomly broke one day.  Visualforce pages now support inline editing; you could do this by overriding the detail page with a Visualforce page now and override its save button to do your bidding.  That would be much more robust.  Just a thought.

sapnajaamdarsapnajaamdar

I got it working for the inline edit page as well!

Here is the update code:

 

document.getElementsByName('inlineEditSave')[0].onclick = function(){
 if(accstatus.value=='Locked'){
   var userchoice =confirm('Are you sure you want to lock the Account?');
   if(userchoice){sfdcPage.save(); return userchoice;}
   else{sfdcPage.revert(); return userchoice;}
 }
 else{sfdcPage.save(); return userchoice;}
};

 

 

This was selected as the best answer
morgan.mamorgan.ma

Hi sapnajaamdar,

  Thanks for your question & answer!

I have the same request, my question is how to add this js code into the case edit page?

I am the new bird here, so would you please help me out?

abhishek_pandey1989@yahoo.comabhishek_pandey1989@yahoo.com
Hey sapna Thank u for the post we have same req here ..if u can pls help .. we want to override the save button of standard object in edit layout and on click of save button while creation of new record(have no idea of jquery)
...pls provide the above code if u can in chronological order and where we should put it(guidelines)....?????

Regards Abhishek
Amit Pal 3Amit Pal 3
Hi Sapna,

Could you please let us know how did u do it on edit page. I am able to do it on inlineedit page but it is causin problems on edit page.
A quick reply will be very helpful. 

Regards.
Ayush UjjainAyush Ujjain
Hi Sapna,
Can you please provide me the code snippet of how to use popup on standard Save functionality.I have the same requirement.

Regards,
Ayush
Ambuj Agrawal 19Ambuj Agrawal 19
please help me with the steps