Skip to content

Instantly share code, notes, and snippets.

@escgeek
escgeek / PO_Approval_Milestones_Helper_Class
Created August 28, 2018 11:20
Apex Class Methods used to build out a child object with Approval and Custom Date metrics in order to do Turn Around Time calculations.
public class PO_Approval_Milestones_Helper_Class {
// Test Class: Global_Test_Class
public static void addTime(List<PO_Approval_Milestones__c> newTrigger){
// Class to calculate the difference in Start and Completed Date/Time Fields
// Doing it at the PO Approval Milestone level in order to cut down on the redundent and complex queries
// 08Dec2017 - ESC
Id bhId;
Id bhDefaultId;
@escgeek
escgeek / master_Trigger_Example
Created August 15, 2018 15:01
Quick Trigger to update a Picklist
trigger master_Latam_Sales_Transactions on Latam_Sales_Transactions__c (before insert, before update) {
// Lines 7-11 are just FYI debug in case there are recursive issues but otherwise are
// not needed and can be deleted.
if(
(Trigger.isUpdate || Trigger.isInsert) &&
Trigger.isBefore
){
String triggerType = 'Update';
if(Trigger.isInsert){
triggerType = 'Insert';
@escgeek
escgeek / Lightning Printable View Page
Created February 13, 2018 20:45
Easy solution to create a printable record page in Salesforce Lightning (Spring 18)
<apex:page standardController="Complaint__c" sidebar="false" title="{!Complaint__c.Name}" showHeader="false">
<apex:form >
<br/>&nbsp;&nbsp;&nbsp;
<!--<br/><u><a href="/{!Complaint__c.Id}">Return to {!Complaint__c.Name}</a></u>&nbsp;-&nbsp;
<apex:commandLink value="Click for Printable View" onclick="window.print();"/> -->
<apex:commandbutton value="<-- Click to Return to {!Complaint__c.Name}" action="/{!Complaint__c.Id}" />&nbsp;&nbsp;&nbsp;
<apex:commandButton onclick="window.print();" value="Print Compliant" />
<apex:detail subject="{!Complaint__c.Id}" relatedList="false" title="false"/>
</apex:form>
</apex:page>
public static void setBUKey(List<Business_Metrics__c> newTrigger){
String buKeyList;
String buKey;
Map<String,Business_Unit__c> buMap = Business_Unit__c.getAll();
for(Business_Metrics__c bmx : newTrigger){
buKey = NULL;
if(bmx.Business_Unit__c != NULL){
buKeyList = bmx.Business_Unit__c;
// This displays the list of users that are active and 'Frozen' in Salesforce.com
SELECT Name, IsActive, LastLoginDate, Id, username FROM User WHERE IsActive = TRUE AND Id IN (SELECT userId FROM userLogin WHERE IsFrozen = TRUE)
map<String, Schema.SObjectField> sMap = Schema.SObjectType.Account.fields.getMap();
map<String, String> fieldMap = new map<String, String>();
for(String s : sMap.keySet())
{
fieldMap.put(sMap.get(s).getDescribe().getLabel(), sMap.get(s));
system.debug('Field Name: ' + sMap.get(s).getDescribe().getLabel() + ' - API Name: ' + sMap.get(s));
}
@escgeek
escgeek / gist:1d698d5e01752b9081a4192d0e1065e4
Last active July 14, 2017 18:39
Apex Test Classes using System.Runas
// Example One - Create the User and run tests under that user
Profile p = [select id from profile where name='System Administrator'];
User u = new User(
alias = 'abc123xyz',
email='unit.test@email123.com',
emailencodingkey='UTF-8',
firstname='Sam',
lastname='Franks',
languagelocalekey='en_US',
localesidkey='en_GB',
@escgeek
escgeek / gist:f3acce6d7a5f6ad1865c6bdb215a2438
Last active July 9, 2017 18:58
Account Page Example with Embedded Wave Dashboard
<apex:page showHeader="true" standardController="Account" sidebar="true">
<p>
<b><a href="/{!Account.Id}">{!Account.Name}</a></b>
</p>
<wave:dashboard dashboardId="0FKn00000004E86GSA" <!-- Fake ID - Use your assetId from Share URL -->
showTitle="false"
showSharing="false"
height="1800px"
openLinksInNewWindow="false"
@escgeek
escgeek / gist:47a07c3029ef65d46982d08cab98426b
Created July 9, 2017 18:40
Embed Wave Dashboard in to Visualforce with more than one filter
Here is the code example straight from the documentation that does not work:
filter="{'Sales_YOY': {'Account__c': ['{!Account.Id}']}}"
Here is the code from the 'bug' page that works:
filter="{'datasets':{'Sales_YOY':[{'fields':['Account__c'], 'filter':{'operator': 'matches', 'values':['{!Account.Id}']}}]}}"
Here is the code that works for multiple datasets:
filter="{'datasets':{
'Sales_YOY':[{'fields':['Account__c.Id'], 'filter':{'operator': 'matches', 'values':['{!Account.Id}']}}],
'Sales_Daily':[{'fields':['Account__c.Id'], 'filter':{'operator': 'matches', 'values':['{!Account.Id}']}}],
q = load "0Fb44000000btGwCAI/0Fc44000000cKRmCAM";
q = filter q by 'Compensatory__c' == "true" && 'Business_Unit__c' == "";
q = group q by ('Business_Unit__c', 'New_Product_Tracking_Name__c');
q = foreach q generate 'Business_Unit__c' as 'BU', 'New_Product_Tracking_Name__c' as 'NPT', sum('Sales__c') as 'Total_Sales';
q = order q by ('BU' asc, 'NPT' asc);
o = load "opportunity";
o = filter o by 'IsClosed' == "false";
o = filter o by date('CloseDate_Year', 'CloseDate_Month', 'CloseDate_Day') in ["current year".."current year"];
o = group o by ('Business_Unit_Formula__c', 'New_Product_Tracking_Name__c');