Skip to content

Instantly share code, notes, and snippets.

View mshanemc's full-sized avatar

Shane McLaughlin mshanemc

View GitHub Profile
@mshanemc
mshanemc / gist:127dfeed535af8763a71
Created February 25, 2015 20:24
Lightning Component Navigation with Fallback
({
update: function(component, evt, helper) {
var expense = component.get("v.expense");
var updateEvent = $A.get("e.c:updateExpenseItem");
updateEvent.setParams({ "expense": expense }).fire();
},
gotoRecord: function(component, evt, helper) {
console.log("onclick");
@mshanemc
mshanemc / responsiveIframe
Created April 24, 2015 15:15
responsive visualforce Iframes
<apex:page showHeader="false" sidebar="false" standardStylesheets="false" docType="html-5.0">
<script type="text/javascript">
//redirect to desktop-only version of page
if( (typeof sforce == 'undefined') || (sforce == null) ) {
if ({!isnull($CurrentPage.parameters.iframeurl)}){
window.location.assign("{!$Page.responsiveIframeDesktop}");
} else {
window.location.assign("{!$Page.responsiveIframeDesktop}?iframeurl={!$CurrentPage.parameters.iframeurl}");
}
@mshanemc
mshanemc / gist:7abd286aa38248ab4f01
Created April 29, 2015 18:19
Customer Depreciation
public with sharing class DepreciationCalc {
public static void deleteCurrentDepreciation(list<Asset__c> assets){
delete [select id from Depreciation__c where Asset__c in:assets];
}
public static void makeDepreciations(list<Asset__c> assets){
list<Depreciation__c> output = new list<Depreciation__c>();
//loop through the assets
@mshanemc
mshanemc / $scope.navigate
Last active August 29, 2015 14:21
Salesforce Universal Navigation in Angular
//universal navigation that works in SF1 or in web desktop UI
$scope.navigate = function(recordId){
if (typeof sforce !== 'undefined'){
sforce.one.navigateToSObject(recordId);
} else {
window.open("/" + recordId,'_blank'); //open in a new window
//window.location.href= "/" + recordId; //open in existing window
//window.top.location.href= "/" + recordId; //open in existing window from inside an iframe, like inline VF or VF in chatter action
@mshanemc
mshanemc / Salesforce1 custom action visualforce redirect page
Created June 1, 2015 19:19
Salesforce1 custom action visualforce redirect page
<apex:page showHeader="false" sidebar="false" standardController="Inspection_Step__c">
<!-- Remote Objects definition to set accessible sObjects and fields -->
<apex:remoteObjects >
<apex:remoteObjectModel name="Inspection_Step__c" jsShorthand="step"
fields="Name,Id,Inspection__c,Step_Number__c,Rating__c">
</apex:remoteObjectModel>
</apex:remoteObjects>
<script type="text/javascript">
@mshanemc
mshanemc / Salesforce profile un-permissioner
Last active August 29, 2015 14:22
Salesforce profile un-permissioner. Run the following 2 scripts from the chrome console to get a no-app, no-object, no-tab user
//first, import jquery
var script=document.createElement('script');
script.type='text/javascript';
script.src='https://code.jquery.com/jquery-latest.min.js';
document.getElementsByTagName('head')[0].appendChild(script);
@mshanemc
mshanemc / metadataSnapshot
Created August 25, 2015 18:40
pull the main metadata for an org (force.com migration tool)
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>*</members>
<name>ApexClass</name>
</types>
<types>
<members>*</members>
<name>ApexComponent</name>
</types>
@mshanemc
mshanemc / QR Code Generation
Created October 29, 2015 21:33
Salesforce formula for QR code
//Salesforce1 deeplink url -- the QR code links to salesforce1://sObject/[Id]/view
IMAGE("https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=salesforce1://sObject/"+Id+"/view", "QR")
@mshanemc
mshanemc / tinyColumns.css
Created September 12, 2016 20:40
lots of columns for SLDS
.slds-size--1-of-13{width: 7.69230769230769%;}
.slds-size--2-of-13{width: 15.3846153846154%;}
.slds-size--3-of-13{width: 23.0769230769231%;}
.slds-size--4-of-13{width: 30.7692307692308%;}
.slds-size--5-of-13{width: 38.4615384615385%;}
.slds-size--6-of-13{width: 46.1538461538462%;}
.slds-size--7-of-13{width: 53.8461538461538%;}
.slds-size--8-of-13{width: 61.5384615384615%;}
.slds-size--9-of-13{width: 69.2307692307692%;}
.slds-size--10-of-13{width: 76.9230769230769%;}
@mshanemc
mshanemc / ExampleCallback.js
Last active February 25, 2021 13:54
Example of Lightning Components for handling Apex Callback Errors
action.setCallback(this, function(a){
if (a.getState() === "SUCCESS") {
//happy path stuff
} else if (a.getState() === "ERROR"){
var appEvent = $A.get("e.c:handleCallbackError");
appEvent.setParams({
"errors" : a.getError(),
"errorComponentName" : "someUniqueName"
});
appEvent.fire();