Skip to content

Instantly share code, notes, and snippets.

View peterknolle's full-sized avatar
💭
🎅

Peter Knolle peterknolle

💭
🎅
View GitHub Profile
@peterknolle
peterknolle / inputFieldIssue.html
Last active September 18, 2019 01:42
Shows the lightning-input-field not working after user input. (1): Click the button and see the lightning-input-field get updated. (2) Manually type something into the lightning-input-field and see it change. (3) Go back and click the button and see the update no longer work.
<template>
<lightning-record-edit-form
object-api-name="Account">
<lightning-input-field
field-name="Name" value={name}></lightning-input-field>
</lightning-record-edit-form>
<lightning-button label="Click to change name" variant="brand" onclick={handleClick}></lightning-button>
/**
* Everything is pass by value in Apex.
* When a method is called the runtime pushes a stackframe on the stack and params
* are created as local vars, including ref vars.
* The object that the ref var points to lives on the heap and can be modified if not immutable.
* The param itself is the ref var and is by value like all params in Apex.
*/
public class A {
public String val { get; set; }
}
@peterknolle
peterknolle / inputRating.cmp
Last active June 25, 2019 16:03
Input Rating Lightning Component
<aura:component >
<ltng:require scripts="/resource/rating/vendor/jquery.js,/resource/rating/lib/jquery.raty.js"
styles="/resource/rating/lib/jquery.raty.css"
afterScriptsLoaded="{!c.afterScriptsLoaded}"/>
<aura:attribute name="value" type="Integer" required="true"/>
<aura:attribute name="ready" type="Boolean" default="false"/>
<div aura:id="rating"></div>
</aura:component>
public class RestRequestController {
@AuraEnabled
public static Response service(String path, String method, String responseFormat, String bodyContent, String bodyContentType) {
HttpRequest request = buildRequest(path, method, responseFormat, bodyContent, bodyContentType);
HttpResponse httpRes = sendRequest(request);
Response restRes = buildResponse(httpRes);
return restRes;
}
@peterknolle
peterknolle / fileSelected.evt
Last active December 29, 2022 17:11
Image Preview Lightning Component
<aura:event type="COMPONENT" description="Event fired when a file is selected">
<aura:attribute name="file" type="Object"
description="The file file input element that has the selected file"/>
</aura:event>
@peterknolle
peterknolle / FileController.cls
Last active January 30, 2023 20:40
Lightning File Upload Component
public class FileController {
@AuraEnabled
public static Id saveTheFile(Id parentId, String fileName, String base64Data, String contentType) {
base64Data = EncodingUtil.urlDecode(base64Data, 'UTF-8');
Attachment a = new Attachment();
a.parentId = parentId;
a.Body = EncodingUtil.base64Decode(base64Data);
@peterknolle
peterknolle / AutocompleteController.cls
Last active December 29, 2022 17:11
Lightning Autocomplete Component
public class AutocompleteController {
@AuraEnabled
public static List<sObject> getSuggestions(String sObjectType, String term, String fieldsToGet, Integer limitSize) {
// could add in logic to remove possible duplicate fields
String fields = fieldsToGet.length() > 0 ? ',' + fieldsToGet : '';
String soql =
' SELECT Name, Id ' + String.escapeSingleQuotes(fields) +
' FROM ' + String.escapeSingleQuotes(sObjectType) +
' WHERE Name Like \'' + String.escapeSingleQuotes(term) + '%\'' +
@peterknolle
peterknolle / remoteAutocomplete.page
Created October 1, 2014 01:06
Remote Objects Autocomplete
<apex:page >
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/smoothness/jquery-ui.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
<apex:remoteObjects >
<apex:remoteObjectModel name="Contact" fields="Name,Id,Email,MobilePhone,Phone"/>
</apex:remoteObjects>
@peterknolle
peterknolle / ContactsController.cls
Last active March 30, 2017 10:20
Remote Objects Infinite Scroll
public with sharing class ContactsController {
@RemoteAction
public static Map<String, Object> retrieveContacts(String type, List<String> fields, Map<String, Object> criteria) {
// Retrieve using the standard retrieve
Map<String, Object> result = RemoteObjectController.retrieve(type, fields, criteria);
// Add in the total record count for the current user.
// This is needed to know when to stop scrolling.
@peterknolle
peterknolle / CORS_MessageService.cls
Last active August 29, 2015 14:05
Accessing Apex REST from Site.com
@RestResource(urlMapping='/v1.0/messages')
global class MessageService {
@HttpGet
global static void getMessages() {
// buildMessages gets FeedItems
List<Message> messages = buildMessages();
RestResponse res = RestContext.response;