Skip to content

Instantly share code, notes, and snippets.

Peter Knolle peterknolle

Block or report user

Report or block peterknolle

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@peterknolle
peterknolle / inputFieldIssue.html
Last active Apr 17, 2019
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.
View inputFieldIssue.html
<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>
View Apex is Pass By Value (exec anon)
/**
* 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 Jun 25, 2019
Input Rating Lightning Component
View inputRating.cmp
<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>
View RestRequestController.cls
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 Jan 18, 2019
Image Preview Lightning Component
View fileSelected.evt
<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 Jul 13, 2019
Lightning File Upload Component
View FileController.cls
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 Jul 25, 2018
Lightning Autocomplete Component
View AutocompleteController.cls
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 Oct 1, 2014
Remote Objects Autocomplete
View remoteAutocomplete.page
<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 Mar 30, 2017
Remote Objects Infinite Scroll
View ContactsController.cls
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 Aug 29, 2015
Accessing Apex REST from Site.com
View CORS_MessageService.cls
@RestResource(urlMapping='/v1.0/messages')
global class MessageService {
@HttpGet
global static void getMessages() {
// buildMessages gets FeedItems
List<Message> messages = buildMessages();
RestResponse res = RestContext.response;
You can’t perform that action at this time.