Save Records in Salesforce via Lightning App

By | August 30, 2016

Salesforce Lightning Component framework is a UI framework for developing dynamic apps for mobile and desktop devices. It’s a modern framework for building single-page applications engineered for growth. Salesforce Lightning makes it easier to build responsive applications for any device. In the earlier blog ‘Retrieve Records via Lightning’, we discussed how to read records from Salesforce and display them via Lightning. Now taking a step ahead, get insights on how to save a record in Salesforce database using Lightning.

Open the developer console. The developer console as we already know is preferred to create Lightning components, controller and apps to preview the functionality. We created a Lightning component named ‘Lightning_SaveRec’ in our developer console which will be used in the Lightning App. First, we write a function in our apex class that would implement the functionality of saving the records, ensure that your method is annotated with ‘@AuraEnabled’. Here’s the snippet for the Apex class handling the functionality of inserting/saving records in Salesforce.

Apex Class for Saving records-Account

Apex Class for Saving records-Account

Now, we need to create a Lightning component which will be using this controller. In your developer console create a new Lightning component. Refer the image below regarding the code snippet for your Lightning component –

Lightning Component-Account

Lightning Component-Account

Now we will write the Lightning controller (JavaScript) that will be used in component and its helper class as well. Please refer the below images for controller and helper class respectively. This would mostly be the functions or actions that will be handled on button click and other such actions at the client side.

Lightning Component controller-Account

Lightning Component controller-Account

Lightning Helper class-

Lightning Helper class-Account

Lightning Helper class-Account

The CSS used in our Lightning component can be downloaded from this link, download SLDS090. Applying the CSS is optional. After downloading the mentioned zip file just upload it in static resources of Salesforce. After implying all the above mentioned steps, just refer the Lightning component in your Lightning app. Once done, just click on “Preview” and then you can view your Lightning App. Once the page is displayed, you can enter the records you want and click on “Submit” button. This will create a new record in your Salesforce SObject.

Lightning App To Save records

Lightning App To Save records

Page side UI-Account

Page side UI-Account

About Us
Greytrix as a Salesforce Product development partner offers a wide variety of integration products and services to the end users as well as to the Partners across the globe. We offers Consultation, Configuration, Training and support services in out-of-the-box functionality as well as customizations to incorporate custom business rules and functionalities that requires apex code incorporation into the Salesforce platform.

Greytrix has some unique solutions for Cloud CRM such as Salesforce integration with Sage Enterprise Management (Sage X3), Sage Intacct, Sage 100 and Sage 300 (Sage Accpac). We also offer best-in-class Cloud CRM Salesforce customization and development services along with services such as Salesforce Data Migration, Integrated App development, Custom App development and Technical Support to business partners and end users.

Greytrix GUMU™ integration for Sage ERP – Salesforce is a 5-star app listed on Salesforce AppExchange.

For more information, please contact us at salesforce@greytrix.com. We will be glad to assist you.

Related Posts