Usage Of lightning-slider

Let us discuss here how to use the lightning-slider. A lightning-slider component is a horizontal or vertical slider for specifying a value between two specified numbers. For example, this slider can be used to capture user input about order quantity or when you want to use an input field of type="range". To orient the slider vertically, set type="vertical". Older browsers that don’t support the slider fall back and treat it as type="text"

Here’s an example of a slider with a step increment of 10.

Handle the change event and get the slider value using the event.target property.

By default, the min and max values are 0 and 100, but you can specify your own values. If you specify your own step increment value, you can drag the slider based on the step increment only. If you set the value lower than the min value, then the value is set to the min value. Similarly, setting the value higher than the max value results in the value being set to the max value.

 

In this example, we will be showing the contact data based on the slide range change

Create Apex Class

create an apex class as shown below

 

LWC 

create a lightning web component using the following sfdx command

 

Use the below slider.html code

 

 

Use the below slider.js code

 

Use the below slider.js-meta.xml

 

Push changes and add it to the page layout and you can able to see the like below

 

 

Usage Of lightning-record-form

Let us discuss here how to use the lightning-record-form . A lightning-record-form component enables you to quickly create forms to add, view, or update a record. Using this component to create record forms is easier than building forms manually with lightning-record-edit-form and lightning-record-view-form. However, lightning-record-form does not support client-side validation quite the same as lightning-record-edit-form.The object-api-name attribute is always required, and the record-id is required unless you’re creating a record.

Modes

The component accepts a mode value that determines the user interaction allowed for the form. The value for mode can be one of the following:

  • edit – Creates an editable form to add a record or update an existing one. When updating an existing record, specify the recordId. Edit mode is the default, and as such, can be omitted.
  • view – Creates a form to display a record that the user can also edit. The record fields each have an edit button.
  • readonly – Creates a form to display a record without enabling edits. The form doesn’t display any buttons.

For all modes, the component expects the fields attribute, the layout-type attribute, or both. Use the fields attribute to specify a comma-separated list of record fields to load into the form. The fields load in the order you list them. Use the layout-type attribute to specify a Full or Compact layout. All fields that have been assigned to the layout are loaded into the form. This is the same behavior as the Lightning Data Service’s force:recordData object. Layouts are typically created or modified by administrators. Loading record data using layout-type allows the form to adapt to those layout definitions. If you provide the fields attribute and the layout-type attribute, the fields specified in the fields attribute are loaded before the layout fields.

This component takes care of field-level security and sharing for you, so users see only the data that they have access to.

Creating a Record

Use mode="edit" and pass in the object API name for the record to be created. Do not specify a recordId. Specify the fields using the fields attribute, or layout-type="Full" attribute to load all the fields defined on the full layout.The compact layout cannot be used for creating records. If you specify layout-type="Compact", the full layout is shown. If you specify the fields attribute, be sure to include any fields that are designated as required for the object’s records. Because no recordId is passed, edit mode loads the form with input fields that aren’t populated with field data. The form displays Submit and Cancel buttons.This example creates an editable two-column form with the full layout and additional fields. The form is used for creating records in an Account object. The onsubmit attribute specifies an action to override the handler for the submit.

Create a Lightning web component using the below SFDX command

Use the below recordform.html code

Use the below recordform.js code

Use the below recordform.js-meta.xml code

 

Push the changes and add this component to the record page layout. you can able to see the complete record create a form

 

Now let’s see how to use create a record with specific fields. Now update the recordform.html code as shown below

Use the below recordform.js code which will be passed to the record form.

Push the changes and you can able to see the create form with two fields as shown below.

Editing a Record

If you do not specify the mode attribute, its default value is edit. To edit a record, pass the ID of the record and the corresponding object API name to be edited. Specify the fields using the fields attribute, or layout-type attribute to load all the fields defined on the Full or Compact layout. When record-id is passed, edit mode loads the form with input fields displaying the specified record’s field values. The form also displays Submit and Cancel buttons. This example creates an editable two-column form with a compact layout and additional fields. The form is used for editing records in an Account object. The onsubmit attribute specifies an action to override the handler for the submit. Update the recordform.html code as shown below.

update the recordform.js code as shown below.

 

Use mode="view" and pass the ID of the record and the corresponding object API name to be displayed. Specify the fields using the fields attribute, or layout-type attribute to display all the fields defined on the Full or Compact layout.

 

the following code shows the how to edit the specific fields instead of layouts.update the recordform.html code as below.

 

update the recordform.js code as shown below.

Now you can able to see the changes as shown below with the specified fields.

Viewing a Record Read-Only

The simplest way to display a record is to use the lightning-record-form. You can display a record in two modes.

view
Loads the form using output fields with inline editing enabled. Editable fields have edit icons. If a user clicks an edit icon, all fields in the form become editable, and the form displays Submit and Cancel buttons.
read-only
Read-only mode loads the form with output fields only. The form doesn’t include edit icons, Submit and Cancel buttons.

This code displays an account record in view mode using the compact layout, which includes fewer fields than the full layout.

Use mode="readonly" and pass the ID of the record and the corresponding object API name to be displayed. Specify the fields using the fields attribute, or layout-type attribute to display all the fields defined on the Full or Compact layout. The read-only mode loads the form with output fields only, and without Submit or Cancel buttons.The following code specifis how to use the read-only mode. Use the below recordform.html code.

You can able to see the record with read-only data .

 

Let’s update the code with view mode as shown below. view Loads the form using output fields with inline editing enabled. Editable fields have edit icons. If a user clicks an edit icon, all fields in the form become editable, and the form displays Submit and Cancel buttons.

Update the code as shown below and you can able to see the edit icon

 

 

Using Record types

If your org uses record types, picklist fields display values according to your record types. You must provide a record type ID using the record-type-id attribute if you have multiple record types on an object and you don’t have a default record type. Otherwise, the default record type ID is used. Display a record create a form based on a record type by providing the record-type-id attribute. This example shows a form that you can place on an account record page. The form displays fields, which include a picklist with values based on the given record type Id.

 

Error Message

To enable automatic error handling, include the component lightning-messages.To customize the behavior of your form when it loads or when data is submitted, use the onload and onsubmit attributes to specify event handlers. Errors are automatically handled. To customize the behavior of the form when it encounters an error on submission or when data is submitted successfully, use the onerror and onsuccess attributes to specify event handlers

 

 

How to Call SOAP Callouts In Lightning Web Components

Let’s discuss here how to use the soap API callouts form the lightning web components(lwc). Apex can also make callouts to SOAP web services using XML. Here we will be using the simple calculator WSDL from the trailhead. please refer to this link for WSDL 

 

Use WSDL2Apex to Generate Apex Code

Use WSDL2Apex to Generate the apex code from the WSDL.

  1. From Setup, enter Apex Classes in the Quick Find box, then click Apex Classes.
  2. Click Generate from WSDL.
  3. Click Choose File and select the downloaded calculator.xml file.
  4. Click Parse WSDL.

It will generate the apex class as shown below.C lick Generate Apex code. The final page of the wizard shows the generated classes, along with any errors.

 

 

Remote Site Settings 

You need to configure authorize endpoint in the remote site settings. Authorize endpoint URL of the web service callout is https://th-apex-soap-service.herokuapp.com 

 

 

Create An Apex Class

Create an apex class with the below code. This class is calling SOAP callouts.

 

 

Create an LWC

 

Create an LWC using the below SFDX command

 

Use the below soapapiex.html code 

 

 

Use the below soapapiex.js code 

 

 

Use the below soapapiex.js-meta.xml code

 

 

 

Push the changes to scratch org using the below command

 

You can able to see the calculator result as shown below.

How to Call SOAP Callouts In Lightning Components

Let’s discuss here how to use the soap API callouts form the Aura lightning components. Apex can also make callouts to SOAP web services using XML. Here we will be using the simple calculator WSDL from the trailhead. please refer to this link for WSDL 

 

Use WSDL2Apex to Generate Apex Code

Use WSDL2Apex to Generate the apex code from the WSDL.

  1. From Setup, enter Apex Classes in the Quick Find box, then click Apex Classes.
  2. Click Generate from WSDL.
  3. Click Choose File and select the downloaded calculator.xml file.
  4. Click Parse WSDL.

It will generate the apex class as shown below.C lick Generate Apex code. The final page of the wizard shows the generated classes, along with any errors.

 

 

Remote Site Settings 

You need to configure authorize endpoint in the remote site settings. Authorize endpoint URL of the web service callout is https://th-apex-soap-service.herokuapp.com 

 

 

Create An Apex Class

Create an apex class with the below code. This class is calling SOAP callouts.

 

 

Create an Aura Component 

 

create an Aura component with the below code. Here is the .cmp markup

Here is the controller.js code

 

 

Add this component to the page layout and you can able to see the output as shown below

 

Get Current User Details in Lightning Web Components

Let’s discuss here how to get the current user details in lightning web components. To access the current user Id, import @salesforce/user/Id in a component’s JavaScript class. Note that @salesforce/user/ cannot be imported by itself; you must indicate the property that you want to import. For the User standard object, only the Id field is available.

 

Option 1: Using Wire Service

You can able to get the current user details using getRecord wire adapter and you can able to pass the user id from the imported modules. Create a new lightning web component using the below SFDX command

Use the below userinfoexample.html code

Use the below userinfoexample.js code

 

Use the below userinfoexample.js-meta.xml

 

Push changes and you can able to see the user details

Option 2: – Using apex class

you can able to get the user detail even using the apex class .create an Apex class that returns the user details as shown below

 

update the userinfoexample.html with below code

 

 

update userinfoexample.js code as shown below

Push changes and you can able to see the current logged in user details