The requirement is to show some messages after Save. Messages would depend on the fields entered for custom object record. The best way which I figured would be to override the standard Save button on the custom object to a visualforce page which would display appropriate messages and then perform save. Not sure how to do that. Please help.

4 Answers 4


Add a field, hidden, of course, that should be set when a message should be displayed. Then, add a hidden Visualforce page to the layout that should reset the flag and show a message when appropriate. The flag can be set from a trigger.

trigger X on Y (before insert, before update) {
    for(Y r: Trigger.new) {
        r.Flag__c = r.Field__c == 'Some Value';


<apex:page standardcontroller="Y" extensions="yExt" action="{!resetFlag}">
    if({!showmessage}) {
        alert("Some informational dialog");


public class yExt {
    ApexPages.StandardController c;
    public Boolean showMessage { get; set; }
    public yExt(ApexPages.StandardController ctrl) {
        c = ctrl;
        showMessage = ((Y)ctrl.getRecord()).Flag__c;
    public void resetFlag() {
        ((Y)c.getRecord()).Flag__c = false;

Drop this into a page layout with a zero-height frame (will make it effectively invisible), and you've got your message alert.

This is only a very basic framework; you might want to make some adjustments based on your exact requirements.


The save button in the standard layout cannot be override. But you can still built a VF page and place your own buttons. But as the above answer says its gonna take whole lot of coding.

All the best.


Sort of depends, your question is a little confusing. On the Detail view page of the object is where you ultimately need to see the message, post-save correct? Since that's the "view" page of the record, see if this will help.

  1. I've done something like this in the past to show more of a "current state of the record" and if you want there to be colors you can use images/icons to make it stand out. So it always shows, might be even better than showing something just after save. Here's how: Create a Formula field to check your fields, and output some text/images or not.

  2. Same idea as above, always showing for the detail/view page. This time create an inline VF page and drop it on the layout. Then you can show anything you want here. (http://blog.jeffdouglas.com/2009/05/08/inline-visualforce-pages-with-standard-page-layouts/)

If you are wanting to show "Field validation errors" upon "click" of the save button and give the user the ability to fix and re-save, then you need to create Validation Rules. https://help.salesforce.com/apex/HTViewHelpDoc?id=fields_defining_field_validation_rules.htm

If the validation rules don't work, sometimes you need to reference other objects, then you need a before insert/update trigger.

If you literally want to display a message ONLY upon successful save, then you need to override the entire Edit page of the record. Lot of work here, but that's how to do it.

  • The edit page wouldn't be appropriate for a successful-save message, exactly. That's more work than what's needed. But formulas are quite useful, and might do the trick.
    – sfdcfox
    Apr 9, 2015 at 5:04

You can't override the Save button unless you override the whole Edit layout, which is not a best practice and there is a lot of effort involved to re-build it. Also it's not scalable for new fields, related lists etc.

I would rather recommend writing a before insert/before update trigger on the Account object that will throw errors accordingly to the record or a particular field.

  • Actually, there's very little work to re-build it. I did so using the REST API (describe layout/record type), and about 100 lines of code. Non-trivial, yes, but not as hard as one might imagine. And, edit pages don't use related lists. OP wants an informational message, not an error.
    – sfdcfox
    Apr 9, 2015 at 5:02
  • True regarding the related list, my bad :). Although why would you re-build the layout when a simple trigger can do the job? At the end of the day it's the business/dev call which approach they take. I always tend to use the KISS method as much as I can Apr 9, 2015 at 5:08
  • I wouldn't rewrite the layout for that purpose. We used this technique to add a real-time address validation popup. The layout was hard coded, so I made it dynamic. Regarding triggers, though, they can't show informational messages, only errors. So, triggers work in some cases, not all.
    – sfdcfox
    Apr 9, 2015 at 5:16
  • Totally agree. I would rebuild the layout for fancy validations and popus etc, though in this case he's after standard error messages (validation style), hence I think a trigger will work better in this scenario Apr 9, 2015 at 5:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.