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
Deeksha Sharma 32Deeksha Sharma 32 

Lightning Save Button customization.

Hi,
I want to e able to save a record(Custom) and also it should post a message to the user based on the criteria. I want to do this by customizing the standard Save button on the lightning Page. Any help on this would be appreciated.
Prakhar Saxena 19Prakhar Saxena 19
Hi Deeksha,

You can override standard Save button functionality and display different messages based on your criteria by writing a method like this:
 
saveRecord : function(component, event, helper) {
        
        var tempRec = component.find("forceRecord");
        tempRec.saveRecord($A.getCallback(function(result) {
            console.log(result.state);
            var resultsToast = $A.get("e.force:showToast");
            if (result.state === "SUCCESS") {
                resultsToast.setParams({
                    "title": "Saved",
                    "message": "The record was saved."
                });
                resultsToast.fire();
                var recId = result.recordId;
                helper.navigateTo(component, recId);
                
            } else if (result.state === "ERROR") {
                console.log('Error: ' + JSON.stringify(result.error));
                resultsToast.setParams({
                    "title": "Error",
                    "message": "There was an error saving the record: " + 
                     JSON.stringify(result.error)
                });
                resultsToast.fire();
            } else {
                console.log('Unknown problem, state: ' + result.state + ', error: ' + 
                JSON.stringify(result.error));
            }
        }));
    }

Follow the following trailhead:

https://trailhead.salesforce.com/content/learn/projects/workshop-override-standard-action

It builds a Lightning component and overrides Standard Actions by using Lightning Data Service.