You need to sign in to do that
Don't have an account?
OnClick Javascript Button to Display Alert AFTER Page Reload?
I have an OnClick Javascript button on the lead record that when clicked, changes the Lead status and refreshes the page. What'd I'd like is for a pop-up window to appear after the page refreshes displaying a message.
I started playing around with the .onload and .reload function, but the alerts I wrote kept appearing upon the button being clicked, not after the page refreshes/reloads. I just want something to pop up and say "Your lead has been updated."
Here's the bottom portion of my code:
// assign values to fields using LeadObj variable
LeadObj.Status = 'Inactive';
LeadObj.Status_Reason__c = 'Lead Unresponsive';
}
//save the change
var result = sforce.connection.update([LeadObj]);
//refresh the page
window.location.reload();
Thanks in advance for any help!
The call that you done to update the record is synchronous in nature.
Thus you can check the result object for the success flag and show the alert based on that.
Can you please try the following:
Below the line : var result = sforce.connection.update([LeadObj]);
add the following code:
if (result[0].getBoolean("success")) {
alert("Operation Successful");
} else {
alert("Operation Failed");
}
Thanks,
Kaustav
All Answers
Please follow the steps below:
1. First add parameter to URL which is set to true before page refresh code i.e window.location.reload(); like code below:
https:abc.com?id=123¶m=true
2. You can use a label in vf page and make it's text visible based on value of parameter passed in URL as below:
jQuery(document).ready(function(){
if({!$CurrentPage.parameters.param== 'true'}){
document.getElementById("thankyoutextid").style.visibility = "visible";
};
});
<apex:outputLabel id="thankyoutextid">Thank You</apex:outputLabel>
Please mark this as best answer if it answers your question, it helps others.
Thanks!
The call that you done to update the record is synchronous in nature.
Thus you can check the result object for the success flag and show the alert based on that.
Can you please try the following:
Below the line : var result = sforce.connection.update([LeadObj]);
add the following code:
if (result[0].getBoolean("success")) {
alert("Operation Successful");
} else {
alert("Operation Failed");
}
Thanks,
Kaustav
@Grazitti, I was hoping to avoid working with visualforce pages, but thank you for chiming in!