Skip to content

Instantly share code, notes, and snippets.

String color = 'Y';
//Expression should be any of the allowable type value
switch on color {
when 'V' {
System.debug('Violet');
}
when 'I' {
System.debug('Indigo');
}
public class ContactAuraController {
@AuraEnabled
Public static List<Contact> getContactList(){
//get all contact list
List<Contact> conList = [SELECT Id, Name, Account.Name, Phone, Email FROM Contact LIMIT 1];
return conList;
}
}
({
doInit : function(component, event, helper) {
//user information
var userData = [{"id":1, "name":"Anil", "city":"Ernakulam", "country":"India"},
{"id":2, "name":"Akhil", "city":"Palakkad", "country":"India"},
{"id":3, "name":"Raju", "city":"Wayanad", "country":"India"},
{"id":4, "name":"Mahesh", "city":"Kannur", "country":"India"}
];
component.set("v.data",userData);
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" access="global" >
<!-- table records are stored on the data attribute -->
<aura:attribute name="data" type="List" access="global" />
<!-- init method loads the data attribute values -->
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
<div class="slds-m-around_xx-large">
<h1 class="slds-text-heading--medium">Simple Contacts</h1>
<table class="slds-table slds-table_bordered slds-max-medium-table_stacked-horizontal slds-p-horizontal_small" role="grid">
<thead>
//Fetching all available attachments in the org
List<Attachment> attachments = [Select Body, Id, Name, OwnerId,ParentId From Attachment];
//System.debug('Attachments'+attachments);
//Details of content version fields are given in the below link
//https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_contentversion.htm
//to map Attachment Id with ContentVersion record
Map<Id,ContentVersion> attachmentCVs = new Map<Id,ContentVersion>();
//Map ---> Attachement - Attachment Parent Id
Map<Id,Id> attachementParentIds = new Map<Id,Id>();
({
addClass : function (element, className) {
//Global Aura util method for adding a style class from an aura element
$A.util.addClass(element,className);
},
removeClass : function (element , className) {
//Global Aura util method for removing a style class from an aura element
$A.util.removeClass(element,className);
},
.THIS .pill-item-size,.THIS .input-container {
width : 100%
}
.THIS .pill-container{
font-size: medium;
margin: .5px;
}
.THIS .input-no-border{
({
onLeaveLookupPane : function(component, event, helper) {
//Search - Input control focus removed on mouse leave
var inputContainerCmp = component.find('master-container');
helper.removeClass(inputContainerCmp,'slds-has-input-focus');
},
remove : function (component, event, helper) {
//Hide the active SLDS - pill
var selectedItemPill = component.find('selected-item-pill');
helper.hideElement(selectedItemPill);
<aura:component >
<aura:attribute name="label" type="String" access="global" default="Search"/>
<aura:attribute name="selectedRecord" type="sObject" default="{name:'Account1'}" />
<aura:attribute name="fetchedRecords" type="List" />
<aura:attribute name="searchText" type="String"/>
<div aura:id="lookUpPane" class="slds-form-element slds-lookup slds-is-close" onmouseleave="{!c.onLeaveLookupPane}">
<label class="slds-form-element__label" for="lookup-text">{!v.label}</label>
<div class="slds-form-element__control">
<div aura:id="master-container" class="slds-combobox_container slds-has-object-switcher">
public class TestApexController {
@AuraEnabled
public static String callApexControllerMethod ( String message, Boolean showError ) {
String counterMessage = 'Response from apex controller - ' + 'Your Message : ' + message;
if (showError) {
throw new AuraHandledException('Custom Exception from the apex controller');
}
return counterMessage;
}