Skip to content

Instantly share code, notes, and snippets.

View douglascayers's full-sized avatar

Doug Ayers douglascayers

View GitHub Profile
<!-- ServiceComponent.cmp -->
<aura:component>
<aura:method name="sum" action="{!c.handleSum}">
<aura:attribute name="a" type="Integer" required="true"/>
<aura:attribute name="b" type="Integer" required="true"/>
</aura:method>
</aura:component>
/* controller.js */
({
onActionConfirmed: function(component, event, helper) {
helper.callServer();
})
@douglascayers
douglascayers / InvocableApexTemplate.cls
Created January 4, 2018 08:15
Example structure of an invocable apex class
public with sharing class InvocableApexTemplate {
@InvocableMethod(
label = 'Name as displayed in Process Builder'
description = 'Tooltip as displayed in Process Builder'
)
public static List<Response> execute( List<Request> requests ) {
List<Response> responses = new List<Response>();
@douglascayers
douglascayers / CaseOpenBizHoursBatchable.cls
Last active April 1, 2019 00:14
Simple batchable to compute the number of hours a case was open, taking into consideration BusinessHours. Can be scheduled to run hourly.
public class CaseOpenBizHoursBatchable implements Database.Batchable<SObject>, Database.Stateful {
private ID businessHoursId { get; set; }
public CaseOpenBizHoursBatchable( ID businessHoursId ) {
this.businessHoursId = businessHoursId;
}
public Database.QueryLocator start( Database.BatchableContext context ) {
// Idea behind this query is to get all open cases or
@douglascayers
douglascayers / GoogleDocToFilesBatchable.cls
Last active February 1, 2023 20:03
Example code to convert GoogleDoc into ContentVersion (external file reference)
public class GoogleDocToFilesBatchable implements Database.Batchable<SObject>, Database.Stateful {
private ID externalDataSourceId { get; set; }
public GoogleDocToFilesBatchable( ID externalDataSourceId ) {
this.externalDataSourceId = externalDataSourceId;
}
public Database.QueryLocator start( Database.BatchableContext context ) {
return Database.getQueryLocator([
@douglascayers
douglascayers / Count.sql
Created September 12, 2017 01:24
Easy way to count attachments or notes by their parent object type. https://twitter.com/DouglasCAyers/status/885892375108866048
SELECT
parent.type,
count(id),
sum(bodyLength)
FROM
Attachment
GROUP BY
parent.type
@douglascayers
douglascayers / DetermineCommonPicklistValues.java
Created June 23, 2017 05:07
Apex example of determining if two multi-select picklist fields contain similar values as asked by https://twitter.com/jeffereyberger/status/877214452453658628
// in apex, the values from multi-select
// picklists are simply delimited strings
String picklistA = 'Apple;Orange;Banana'; // obj1.picklist__c
String picklistB = 'Apple;Pear;Plum;Orange'; // obj2.picklist__c
// split the strings into individual values and store as unique sets
Set<String> picklistValuesA = new Set<String>( picklistA.split(';') );
Set<String> picklistValuesB = new Set<String>( picklistB.split(';') );
System.debug( 'picklistValuesA: ' + picklistValuesA );
@douglascayers
douglascayers / VisualforceJavaScriptDesignPattern.html
Last active August 28, 2019 08:44
Visualforce and JavaScript design pattern to handle page load and ajax rerendering events.
<apex:page extensions="SomeController">
<script src="{!$Resource.jquery224}"></script>
<script>$j = jQuery.noConflict();</script>
<apex:form>
<apex:outputPanel id="someSection">
... stuff here ...
@douglascayers
douglascayers / UploadFile.html
Last active April 18, 2021 14:48
JavaScript snippet for uploading fille to Salesforce as ContentVersion and sharing to record as ContentDocumentLink via jsforce and jquery.
<apex:page>
<head>
<script src="{!$Resource.jquery224}"></script> <!-- https://jquery.com/ -->
<script src="{!$Resource.jsforce170}"></script> <!-- https://jsforce.github.io/ -->
<script>$j = jQuery.noConflict();</script>
</head>
<body>
<form>
@douglascayers
douglascayers / ContentHubTest1.cls
Last active July 14, 2023 10:04
ConnectApi.ContentHub examples of adding and updating files in external data source (e.g. Google Drive or SharePoint Online) before Summer '17
/**
* Developed by Doug Ayers (douglascayers.com)
* Org62 Case 16584902
* GUS W-006274
*
* This test creates a file "new document.txt" with contents "Hello World"
* in an external data source, such as Google Drive or SharePoint Online.
*
* Despite being a unit test it has real side effects in the external system.
*