You need to sign in to do that
Don't have an account?

Display save success message only when the record is saved on VF page
I've a VF page to create cases. It has lot of workflows and VRs associated with it. While saving a record, if there's a VR error, the message shows at the top of page, however, I'm also able to see Save success message beneath the VR message. How do I restrict save success message to be displayed only when the record is actually saved? Please refer the attached screenshot and controller.
ease refer to the below screenshot.
public class QRreportController /* --------------------- variable for the standard controller ------------------------------- */ { private ApexPages.StandardController std; /* --------------------- variable for this case ------------------------------- */ public Case c {get; set;} /* -------------------- standard work order controller ---------------------------- */ public QRreportController (ApexPages.StandardController stdCtrl) { // prepopulates some fields on page load this.c = (Case)stdCtrl.getRecord(); Map<ID,Schema.RecordTypeInfo> rt_Map = Case.sObjectType.getDescribe().getRecordTypeInfosById(); Id RecordTypeIdCase = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Quality Report Case').getRecordTypeId(); Id rtId = RecordTypeIdCase; c.RecordTypeId=rtId; c.AccountId=System.currentPageReference().getParameters().get('AccountId'); std=stdCtrl; } /* --------------------- Get Case ------------------------------- */ public Case getCase() { return (Case) std.getRecord(); } public Attachment attachment { get { if (attachment == null) attachment = new Attachment(); return attachment; } set; } /* --------------------- Save and Exit method ------------------------------- */ public PageReference saveAndExit() { std.save(); PageReference pageRef1 = new PageReference('/' + getCase().id); return pageRef1; } /* --------------------- Edit method ------------------------------- */ public PageReference edit1() { PageReference pageRef2 = Page.QRcaseEdit; pageRef2.getParameters().put('id', getCase().id); pageRef2.getParameters().put('AccountId', getCase().AccountId); return pageRef2; } /* --------------------- Quick Save method ------------------------------- */ public PageReference save() { std.save(); PageReference pageRef3 = Page.QRcase; ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'SUCCESS! Changes saved.')); pageRef3.getParameters().put('id', getCase().id); pageRef3.getParameters().put('AccountId',getCase().AccountId); return PageRef3; } public PageReference upload() { attachment.OwnerId = UserInfo.getUserId(); attachment.ParentId = getCase().Id ; // attachment.IsPrivate = true; try { insert attachment; } catch (DMLException e) { ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment')); return null; } finally { attachment = new Attachment(); } ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully')); return null; } }
ease refer to the below screenshot.