Skip to content

Instantly share code, notes, and snippets.

public class TowerMapController {
@AuraEnabled
public static List<Tower__c> getAllTowers() {
String theObject = 'Tower__c';
List<String> theFields = new List<String>{'Id', 'Name', 'State__r.Name', 'Location__Latitude__s', 'Location__Longitude__s'};
List<String> theFilters = new List<String>();
String sortField = 'Name';
String sortOrder = 'ASC';
List<Tower__c> allTowers = UtilityClass.queryObjects(theObject, theFields, theFilters, sortField, sortOrder);
return allTowers;
public class UtilityClass {
public static List<sObject> queryObjects(String theObject, List<String> theFields, List<String> theFilters, String sortField, String sortOrder) {
String theQuery = 'SELECT ' + string.join(theFields, ',');
theQuery += ' FROM ' + theObject;
boolean firstFilter = true;
for(String filter : theFilters) {
String clauseToUse = (firstFilter) ? ' WHERE ' : ' AND ';
filter = filter.trim();
filter = filter.replaceAll('(\\s+)', ' '); // removing white spaces
theQuery += clauseToUse + filter;
<apex:page controller="InheritedSharingClass">
   <apex:repeat value="{!allTheSecrets}" var="record">
       {!record.Name}
   </apex:repeat>
</apex:page>
public inherited sharing class InheritedSharingClass{
   public List<Contact> getAllTheSecrets(){
       return [SELECT Name FROM Contact];
   }
}
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="contactList">
<apiVersion>45.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
<target>lightning__RecordPage</target>
<target>lightning__HomePage</target>
</targets>
</LightningComponentBundle>
import { LightningElement, wire } from 'lwc';
import getContactList from '@salesforce/apex/ContactController.getContactList';
export default class EventBubbling extends LightningElement {
@wire(getContactList) contacts;
}
<template>
<template if:true={contacts.data}>
<template for:each={contacts.data} for:item=contact>
<a href="#" key={contact.Id} data-contact-id={contact.Id} onclick={handleSelect}>
<lightning-layout>
<lightning-layout-item>
<img src={contact.Pcture__c} alt="Profile Photo"/>
</lightning-layout-item>
<lightning-layout-item padding="horizontal-small">
<p>{contact.Name}</p>
public with sharing class ContactController {
@AuraEnabled(cacheable=true)
public static List<Contact> getContactList() {
return [SELECT Id, Name, Title, Phone, Email, Picture__c FROM Contact WHERE Picture__c != null LIMIT 10];
}
}
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="helloConditionalRendering">
<apiVersion>45.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
<target>lightning__RecordPage</target>
<target>lightning__HomePage</target>
</targets>
</LightningComponentBundle>
import { LightningElement, track } from 'lwc';
export default class HelloConditionalRendering extends LightningElement {
@track areDetailsVisible = false;
handleChange(event){
this.areDetailsVisible = event.target.checked;
}
}