Apex Class:
public with sharing class ExampleController {
@AuraEnabled(cacheable=true)
public static List < Account > fetchAccounts() {
return [ SELECT Id, Name, Industry, ( SELECT Id, FirstName, LastName FROM Contacts ) FROM Account LIMIT 10 ];

}

}
LWC HTML:
<template>
<lightning-card>
<div class="slds-m-bottom_small">
<lightning-button
label="Collapse All"
onclick={clickToCollapseAll}>…

HTML:
<template>
<lightning-card title="Prechat Form">
<template if:true={errorMessage}>
<div style="color:red;font-weight:bold;">
{errorMessage}<br/>
</div>
</template>
<template class="slds-m-around_medium" for:each={fields} for:item="field">
<div key={field.name}>
<lightning-input
key={field.name}
name={field.name}
label={field.label}
value={field.value}
max-length={field.maxLength}
required={field.required}> …




Aura Component:
<aura:component implements="lightningsnapin:prechatUI">
<lightningsnapin:prechatAPI aura:id="prechatAPI"/>
<aura:handler name="init" value="{!this}" action="{!c.onInit}" />
<aura:attribute name="startBool" type="Boolean" default="false"/>
<aura:attribute name="errorBool" type="Boolean" default="false"/>
<aura:attribute name="firstName" type="Boolean" default="false"/>
<aura:attribute name="lastName" type="Boolean" default="false"/>
<aura:attribute name="email" type="Boolean" default="false"/>
<aura:attribute name="subject" type="Boolean" default="false"/>
<aura:attribute name="prechatFieldComponents" type="List" description="An array of objects representing the pre-chat fields specified in pre-chat setup."/>
<h2>Prechat form</h2>
<div>
Claims FAQs …

Apex Class:
public with sharing class LoggedInUserCheckController {

@AuraEnabled( cacheable = true )
public static Boolean loggedInAsUserCheck() {

Boolean loggedInAsUserBool = false;
Map < String, String > currentSessionInfo = Auth.SessionManagement.getCurrentSession();

if ( currentSessionInfo.get( 'LoginHistoryId' ) == null &&
currentSessionInfo.get( 'LoginType' ) == 'Unknown' &&
currentSessionInfo.get( 'LogoutUrl' ) == null ) {

loggedInAsUserBool = true;

}
return loggedInAsUserBool;

}
}LWC:
HTML:
<template>
<lightning-card>
Loggged in as Community User? {loggedInAsUserBool}
</lightning-card>
</template>
JavaScript:
import { LightningElement, wire } from 'lwc';
import loggedInAsUserCheck from '@salesforce/apex/LoggedInUserCheckController.loggedInAsUserCheck';
export default class LoggedInUserCheck extends LightningElement {…

Sample Code:Apex Class:public class SampleAuraController {

@AuraEnabled
public static List < Knowledge__kav > fetchArticles() {

return [ SELECT Id, Title FROM Knowledge__kav LIMIT 5 ];

}
}
Component:<aura:component implements="force:appHostable" controller="SampleAuraController">
<aura:handler name = "init" value = "{!this}" action = "{!c.onInit}"/>
<aura:attribute type="Knowledge__kav[]" name="articleList"/>
<lightning:card>
<lightning:tabset>
<aura:iteration items="{!v.articleList}" var="item">
<lightning:tab label="{!item.Title}" id="{!item.Id}">
<lightning:recordForm
recordId="{!item.Id}"
objectApiName="Knowledge__kav"
layoutType="Full"
mode="view" />
</lightning:tab>
</aura:iteration>
</lightning:tabset>
</lightning:card>
</aura:component>

Magulan Duraipandian

18x Salesforce Certified, Lightning Champion, Technical Author. Blogger blogging in www.infallibletechie.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store