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
sekhar 131sekhar 131 

how to create Save and New Button in Lightning Component

how to create Save and New Button in Lightning Component
hi
Please help me 
mukesh guptamukesh gupta
Hi Sekhar,

you can use 
<lightning:button aura:Id="SaveBtn" label="save" onclick="{!c.savecontact}"/>

If this solution is usefull for you, Please mark as a Best Answer to help others.



Regards
Mukesh
Khan AnasKhan Anas (Salesforce Developers) 
Hi Sekhar,

Greetings to you!

Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.

Apex:
public class SaveAndNewC {
    
    @AuraEnabled
    public static Id saveDetails(Account regForm1){
        // DML operation to save Account Details   
        INSERT regForm1;
        return regForm1.Id; 
    }
}

Component:
<aura:component controller="SaveAndNewC"
                implements="lightning:isUrlAddressable,force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="PageHeading" type="String" default="Create Account"/>
    <aura:attribute name="RegForm" type="Account" default="{'sobjectType' : 'Account'}"/>
    
    <div class="slds-m-top--xx-large">
        <div class="slds-page-header">
            <div class="slds-align--absolute-center">
                <div class="slds-text-heading--large">       
                    {!v.PageHeading}
                </div>
            </div>
        </div>
    </div>
    <br/> <br/>
    
    <div class = "slds-size--3-of-8">
        <lightning:input label="Enter Account Name" name="accName" value="{!v.RegForm.Name}"/>
        <br/>
        <lightning:input label="Enter Phone" name="accPhone" value="{!v.RegForm.Phone}"/>
        <br/>
        <lightning:input label="Enter Website" name="accWebsite" value="{!v.RegForm.Website}"/>
        <br/>
        <lightning:button label="Submit" onclick="{!c.doSubmit}"/>
    </div>
</aura:component>

Controller:
({
    doSubmit : function(component, event, helper) {
        var regForm = component.get("v.RegForm");
        var action = component.get("c.saveDetails");
        action.setParams({regForm1  : regForm});
        action.setCallback(this, function(response) {
            var state = response.getState();          
            if (state === "SUCCESS") {
                var res = response.getReturnValue();
                component.set('v.RegForm','');
            }
            else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        console.log("Error message: " + 
                                    errors[0].message);
                    }
                } 
                else {
                    console.log(response.getReturnValue());
                }
            }
        });
        $A.enqueueAction(action);
    },
})

CSS:
.THIS {
    
}

.THIS.slds-size--3-of-8 {
    
    margin-left: 430px;
}

.THIS label.slds-form-element__label{
    
    font-size: 1.00rem;
    color: blue;
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
sekhar 131sekhar 131
Hi Mukesh
not Save Button
My Requred "Save and New" Button
Please Forword the Action function 

 
sekhar 131sekhar 131
Hi Khan Anas 
This Code Not working
Khan AnasKhan Anas (Salesforce Developers) 
Sekhar, it is working fine, see screenshot. Please check your code again.

User-added image

Regards,
Khan Anas
sekhar 131sekhar 131
User-added image

Hi 
how To Designe the same page in lightning