How to display alert on Salesforce Standard/Custom object Page Layouts?
This post describes how to display alert on Standard or/custom page layouts based on specific field value. Here I am going to explain this scenario for Account Layout. If I open an account record where “Display_Alert__c” equals true, I need a pop to display.
To achieve this we need to create a visualforce to display popup. And place this visualforce page on page layout you want to display.
Fallow below steps to implement this solution.
- I have created a custom field on Account object with data type checkbox. Field name is “Display_Alert__c”
- Create a visualforce page “AccountAlertLayoutPage” to display alert. I created this page with below code.
<apex:page standardController="Account">
<script>
if({!Account.Display_Alert__c})
alert('Display Alert!!');
</script>
</apex:page>
- Next go to Account page Layout and add visualforce page created above to the Account PageLayout.
Setup -> Customize -> Account -> Page Layout
Click Edit next to the page layout and add visualforce. Click on visualforce settings change width & height to “0”. And also uncheck “show scrollbars & show labels”.
To test this Create an Account record with required fields and also check “Display_Alert__c” checkbox. Next open this record, you will get alert checkbox.
You can change popup message on visualforce page based on your requirement. You can implement this for any type of field based on your requirement. And you can implement your own visualforce based on your requirement.
I am getting the below error when I am creating a new account record. Please help.
URL No Longer Exists
You have attempted to reach a URL that no longer exists on salesforce.com.
You may have reached this page after clicking on a direct link into the application. This direct link might be:
• A bookmark to a particular page, such as a report or view
• A link to a particular page in the Custom Links section of your Home Tab, or a Custom Link
• A link to a particular page in your email templates
If you reached this page through a bookmark, you are probably trying to access something that has moved. Please update your bookmark.
If you reached this page through any of the other direct links listed above, please notify your administrator to update the link.
If you reached this page through a link on our site, please report the broken link directly to our Support Team and we will fix it promptly. Please indicate the page you were on when you clicked the link as well as any other related information. We apologize for the inconvenience.
Thank you again for your patience and assistance. And thanks for using salesforce.com!
Thanks in advance.
Are you trying to create record on Salesforce Account object by using Account tab?
I created the VisualForce page as shown above and when I created a new record within the custom object and checked the Display Alert box, saved, and reopened, no popup appeared when testing. What did I do wrong?
I know this is a late answer but I think this could be useful for people who are still looking for answer from this thread. I had the same problem. I tried to have the function displayed text from a field and it turns out that the alert message only poped up when the field is empty. So I checked the syntax and the followign code worked for me:
window.onload = function(){
if({!Account.DisplayAlert__c}){
alert(“{!Account.AlertMessage__c}”)
}
}
Note that you need the “” Sign for the text field to display.
Hope this help 🙂
I am also getting the above error message. I have created an account from the Account tab, I get the pop up window, when I click on the ‘OK’ button I am redirected to the “URL No Longer Exists” page.
I used this to successfully create an alert but when used in Chrome, the popup is auto-disappearing after half a second. How can I get the alert to remain until dismissed via button click by the user?