Salesforce LWC - How to create record into custom object using LWC Component?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hello friends welcome to AI tech1.com my name is Sumit and first of all I would like to welcome all of you in the video series for Salesforce likely web components in my previous video of lwc series have explained that how do we create a record into a standard object by using records form how do we preview the report by using record view form and how do we display the resource on a lightning webcom so the topic for today video is how do we create record into custom object using 10wp I received comment from most of the most of the viewers and they would like to know that how do we add a record into a custom object because they were trying to do that and they were they were failed to do this so therefore I decided why not recorder video on that so before I begin and explain you how do we do that don't forget to subscribe the YouTube channel and uh you can also press the Bell icon to receive the updates on the new videos so let's begin and let me explain you that how do we add a record into a custom object by using lwc and in order to explain this example what I have done uh I will be using the an example where I've created one I'm using recruitment application which I used to create in my trainings and there's a candidate object in that application so I would like to create a new lightning web component in order to add new candidate reports so I have already done that let me show you and as you can see this is a lightning web component I have created this is my lightning component and this lightning component helps to add a new record into candidate objects so once we fill up all the details require details and click on save it will submit the data to add a new record into candidate object and it will display a proper message so how I have designed this so the very first thing is I've used Visual Studio code and in the visual studio code I created a new lightning web combo so those who are new to this series and they might not uh they don't have any idea how do we create a writing web company so they can check my first video in lwc series whether when I have explained how do we create how do we design a lightning web component using visual studio code and to deploy that lightning web component on Salesforce platform so the very first thing as very first step I did here is I just created a new lightning web component and my component name is add custom lwc and here's an option to create a lively web form let me show you one quickly so lightly webcam XML I just seen the required information I set this to two and I would like to deploy this lightning web component on three locations on the application page on a home page or other tab that is my text the second step is I just created one lwc FX class and in order to create a class you can see we've got a class option under Force app main default this is the class and then right click and create an effects this is my class and in this class I simply explained that I just simply added a function called add new candidate function with three parameters so this function takes three parameters as an input name candidate name candidate email IDs and candidate phone as box screen type there would be no return uh there would be no return like will not be returning any value so return type because of the void and at the rate or unable answer and what I did I simply add the I just create a new instance for the candidate object and add just pass the values to assign the values and simply insert before so this is our FX class now let's let me show you the HTML so this is my lightning web component HTML and this HTML what I have done in this HTML in this HTML I simply add the I just created like the card title new candidate and lightning info so I'm I just added three input field because I need to get input uh candidate name email address and phone number so the first input is candidate name and the function is F9 scene Handler second keyless email label as email address and on sale email chain handle and the third is telephone label is phone number and the phone number and then there's a button the variant type is brand and the label is save record and the title create mean candidate and on click I'm going to call handle click function so this is what I see this is what I added in dot HTML now let's move to the client-side JavaScript or the lightning web component JavaScript this is my JavaScript and this JavaScript first of all I add decorators like drag decorator API I haven't used it but I have added it just in case you want to use it further if you don't want it you can get rid of you can remove this don't add it because I haven't used this API anywhere right now then I just added three Fields The Wave used to declare the fields in uh in order to add new record into a custom object in same manner but the only thing is you will not be able to get like when you try to get this kind of information you won't get it the under the schema for example let me show you are just right here import so if I just write here in 4 yes from and the rate Salesforce I would be getting a schema for all the accounts only for the standard account not for the customer customer so therefore we have to add it by ourselves so I just copied it for the standard one and I then I replaced the standard one with my customer so therefore I added a candidate object candidate that's the APN my candidate object.undi dot email ID and Dot these are the field labels foreign in order to display the confirmation message or the error message then I declare one uh I declare one site here which contains three three like three variables first name three you can say that's a single property this contains three values for personal phone and email and we map these fields with the email ID to have name and phone number and then what I did uh based on the phone chain Handler like f93 Handler email chain Handler and phone chain Handler whatever values we type in into these fields so these values we have to assign to the variables and that's what we are doing here so with the help of these three three functions we will be assigning the values into the variables respectively into this student details of first links to detail.phones to detail.eu so I just assigned the values then whenever user click on a button it is going to call the handle click function and in this handle click function as you can see I invoke that function add new candidate now add new candidate basically this is the function in ardu candidate and don't forget the reference of this function we have added here just add new family so this is our new candidate and here as you can see this function page three parameters as an input so here I am passing three parameters candidate no candidate name candidate email writing can form and be very careful the the field uh the parameter name should be same exactly same can dot name can email and can if I use the same attribute means or the parameters need and we just assign the values to them so whatever value we whatever value is there in the student detail DOT first name I find this you can name same to the email address and then in order to display the error message and all the confirmation message I just display I just use this block so basically what this block will do this block will show the message display the message it must show toasty so once it is done successfully what we have to do once everything is okay what we have to do we have to finally right click and deploy the source to all so we have to deploy the FX Cloud we have to deploy this lwc component with all the three files we registered we created we need to deploy them onto Salesforce platform I have done that and now I just add that lwc component here and I have already explained previously also that how do we add this component here how do we do that fine so so now let's test it so in order to test it as you can see there are 47 records and I'm going to write here let's say AI Tech or let me add a name as let's say Peter Paul email ID actually I I might have Peter Paul already registered let me just name as a different name let me give a different name um let me give name as David gmail.com and phone number and when I click on Save you can see I got a confirmation message new candidate David created successfully less than verify the record when I refresh you can see a new record added successfully here candidate name David candidate number sorry candidate number 48 name email ID and phone number so like this way we can pass more parameters so to fill up all the required details so that's the way we success that's the way we used to create or we used to add a report into a custom object by using lightning web company so that's all in this video if you like this video don't forget to press the like button you can post your comments in comment box you can reach out to us for the customized training on Salesforce you can visit our website for more updates or you can contact us on the given numbers keep watching keep programming have a nice day bye
Info
Channel: AITECHONE
Views: 4,750
Rating: undefined out of 5
Keywords: Salesforce lwc, custom record in lwc, addrecordlwc, lwctutorial, lwcdiy, lwcDIY
Id: VYR0HVymnaM
Channel Id: undefined
Length: 11min 12sec (672 seconds)
Published: Sat Jul 15 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.