Skip to content

Instantly share code, notes, and snippets.

View rapsacnz's full-sized avatar
🏠
Working from home

Caspar Harmer rapsacnz

🏠
Working from home
View GitHub Profile

To escape the current context and run as the "Automated Process" user (high priviliges), do this:

First define a platform event. For example: Async_Message__e with a paylod and a type.

Then define an AsyncActionUtil class. This will contain a way of inserting these platform events and handling them after insert. The class should contain an insert method:

public static void insertAsyncMessage(String type, String payload) {
  Async_Message__e[] messages = new List<Async_Message__e>{
    new Async_Message__e(Type__c = type, Payload__c = payload)

};

[
{
"Type": "Curriculum",
"TitleCurriculum": null,
"MEntryList": null,
"LpSeqList": null,
"LpEntryList": null,
"CuSeqList": null,
"CoEntryList": [
{
@rapsacnz
rapsacnz / Books.txt
Created February 27, 2019 02:35
Books Read By Kris Gray That I Haven't Read
A Game of Thrones
The Moon is a Harsh Mistress
Jurassic Park
Chasm City
A Clash of Kings
A Storm of Swords
A Feast of Crows
A Dance with Dragons
Heir to the Empire
Lord of the Silver Bow
@rapsacnz
rapsacnz / ScriptLoadHelper.js
Created September 10, 2018 18:39
Load up scripts using Promises in Lightning
getResouce: function(component, scriptName, resourceName) {
return new Promise($A.getCallback(function(resolve, reject) {
if (component.get("v.scriptsLoaded") == true) {
resolve(window[scriptName]);
}
else {
// Create script element and set attributes
var script = document.createElement('script');
@rapsacnz
rapsacnz / Utilities.cls
Created June 20, 2017 22:01
Apex Utilities
/**
* Created by caspar on 20/05/16.
*/
public without sharing class Utilities {
public static Map<String, List<String>> fieldsForType = new Map<String, List<String>>();
/**
* Retrieves a list of sObjects
<apex:page applyBodyTag="false" controller="YourController" extensions="LookupController" docType="html-5.0" showHeader="true" sidebar="false" standardStylesheets="false">
<html xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg">
<head>
<apex:includeScript value="/lightning/lightning.out.js"/>
<apex:stylesheet value="{!URLFOR($Resource.SLDS0110, 'assets/styles/salesforce-lightning-design-system-vf.css')}"/>
</head>
<body >
<div class="slds">
<div class="slds-form-element slds-m-top--xx-small">
<div class="slds-m-right--x-small" id="account_lookup"></div>
<Row ss:Height="19">
<Cell ss:StyleID="s67"/>
<Cell ss:StyleID="s67"><Data ss:Type="String">Totals</Data></Cell>
<Cell ss:StyleID="s67" ss:Formula="=SUM(Amount_Column)"><Data ss:Type="Number"></Data></Cell>
<Cell ss:StyleID="s70" ss:Formula="=SUM(Percentage_of_Total_Column)"><Data
ss:Type="Number"></Data></Cell>
</Row>
<apex:repeat value="{!opportunities}" var="opp">
<Row>
<Cell ><Data ss:Type="String">{!opp.Name}</Data>
<NamedCell ss:Name="Name_Column"/></Cell>
<Cell ><Data ss:Type="String">{!opp.StageName}</Data>
<NamedCell ss:Name="Stage_Column"/></Cell>
<Cell ><Data ss:Type="Number">{!opp.Amount}</Data>
<NamedCell ss:Name="Amount_Column"/></Cell>
<Cell ss:StyleID="s75" ss:Formula="=IFERROR(RC[-1]/Total_Amount_Cell,0)"><Data
ss:Type="Number"></Data>
<Names>
<NamedRange ss:Name="Amount_Column" ss:RefersTo="=Opportunities!R2C3:R{!oppSize + 1}C3"/>
<NamedRange ss:Name="Name_Column" ss:RefersTo="=Opportunities!R2C1:R{!oppSize + 1}C1"/>
<NamedRange ss:Name="Percentage_of_Total_Column" ss:RefersTo="=Opportunities!R2C4:R{!oppSize + 1}C4"/>
<NamedRange ss:Name="Stage_Column" ss:RefersTo="=Opportunities!R2C2:R{!oppSize + 1}C2"/>
<NamedRange ss:Name="Total_Amount_Cell" ss:RefersTo="=Opportunities!R{!oppSize + 2}C3"/>
</Names>
<apex:page id="pg" standardStylesheets="false" controller="ExcelExportController"
contenttype="application/vnd.ms-excel#TestExport_{!TODAY()}.xls">
<apex:outputText value="{!xmlheader}" escape="false"/>
<!-- your excel output goes here -->
<apex:outputText value="{!endfile}" escape="false"/>
</apex:page>