Skip to content

Instantly share code, notes, and snippets.

@sohalloran
sohalloran / OpportunityTrigger.trigger
Created April 30, 2018 13:39
Opportunity Programatic Share - Reinsert Shares after ownership change
trigger OpportunityTrigger on Opportunity (before update) {
Set<Id> ownerChangeOppIds = new Set<Id>();
for (Opportunity opp : Trigger.new) {
if(opp.ownerId != Trigger.oldMap.get(opp.Id).OwnerId) {
ownerChangeOppIds.add(opp.Id);
}
}
if(!ownerChangeOppIds.isEmpty()) {
String oppShares = JSON.serialize([select opportunityId, UserOrGroupId, OpportunityAccessLevel, RowCause
from OpportunityShare
var action = component.get("c.getItems");
action.setStorable();
action.setCallback(this, function(response) {
// handle response
};
$A.enqueueAction(action);
@sohalloran
sohalloran / MathSvc.cmp
Created April 30, 2018 19:49
*Using a Service Component Example App*
<aura:component >
<aura:method name="add" action="{!c.add}" access="public">
<aura:attribute name="numbers" type="Double[]"/>
</aura:method>
<aura:method name="square" action="{!c.square}" access="public">
<aura:attribute name="number" type="Double"/>
</aura:method>
</aura:component>
// Controller //
<aura:event type="COMPONENT">
<aura:attribute name="message" type="String"/>
</aura:event>
@sohalloran
sohalloran / AccountsList.cmp
Last active May 1, 2018 14:26
Reuseable Lightning Data Service Component
<aura:component extends="c:DataSvc" controller="AccountsListController">
<aura:attribute name="rows" type="Object[]" description="The row data."/>
<aura:attribute name="columns" type="List" default="[{label:'Id', fieldName: 'Id', type: 'text'},{label:'Name', fieldName: 'Name', type: 'text'}]"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<lightning:datatable data="{!v.rows}" keyField="Id" columns="{!v.columns}"/>
</aura:component>
//CONTROLLER
@sohalloran
sohalloran / ErrorLoggingSvc.cmp
Last active May 1, 2018 15:15
Lightning Logging Service Component
<aura:component >
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="newLogRec" type="Error_Log__c" />
<aura:attribute name="newLog" type="Error_Log__c" />
<aura:attribute name="logError" type="string" description="Error message returned by logging service" />
<force:recordData aura:id="errorLogCreator"
layoutType="FULL"
targetRecord="{!v.newLogRec}"
@sohalloran
sohalloran / EmailSend.cmp
Created July 30, 2018 17:08
Email Handling for Opportunity
<aura:component controller="EmailSendController" implements="force:lightningQuickAction,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global">
<!--Part 1 [for attribute declare]-->
<aura:attribute name="email" type="string"/>
<aura:attribute name="subject" type="string"/>
<aura:attribute name="body" type="string"/>
<aura:attribute name="mailStatus" type="boolean" default="false"/>
<!---Part 2 [header part] -->
<div class="slds-page-header" role="banner">
<h1 class="slds-page-header__title slds-m-right--small slds-align-middle slds-truncate" title="this should match">
<aura:component implements="flexipage:availableForAllPageTypes,forceCommunity:availableForAllPageTypes" extensible="true">
<aura:method name="execApex" action="{! c.execApex }">
<aura:attribute name="callingComponent" type="Aura.Component" default="{! this }" />
<aura:attribute name="method" type="String" />
<aura:attribute name="params" type="Map" />
</aura:method>
{! v.body }
@sohalloran
sohalloran / DX
Created December 6, 2018 10:59
SFDX Bash Script - Shows a menu of commonly used commands
#!/bin/bash
# SFDX menu for my most commonly called commands
#
function run {
echo
echo $1
eval "$1"
echo
}
#!/bin/sh
# Create a live agent session, polling every second for messages
#
domain="https://[DOMAIN-HERE]salesforceliveagent.com"
orgid="ORG-ID-HERE"
deploymentid="DEPLOYMENT-ID-HERE"
buttonid="BUTTON-ID-HERE"
createchat ()
{