Skip to content

Instantly share code, notes, and snippets.

View jongpie's full-sized avatar
☁️

Jonathan Gillespie jongpie

☁️
View GitHub Profile
@jongpie
jongpie / Analyse.cls
Created February 3, 2017 20:36
See API version for classes, pages & triggers
// ApexClass
System.debug('Starting ApexClass analysis');
Map<Decimal, Integer> apexClassMap = new Map<Decimal, Integer>();
List<ApexClass> apexClassList = [
SELECT Id, Name, ApiVersion
FROM ApexClass
WHERE NamespacePrefix = null
AND (NOT Name LIKE '%Test')
ORDER BY ApiVersion, Name
];
@jongpie
jongpie / Abort.cls
Created February 3, 2017 20:41
Abort all scheduled jobs
for(CronTrigger cronJob : [SELECT Id, CronExpression,CronJobDetailId, CronJobDetail.Name, CronJobDetail.JobType FROM CronTrigger]) {
System.abortJob(cronJob.Id);
}
@jongpie
jongpie / CustomPermissionsReader.cls
Created February 24, 2017 09:30 — forked from afawcett/CustomPermissionsReader.cls
CustomPermissionsReader
/**
* Copyright (c), Andrew Fawcett
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
trigger AccountTrigger on Account(before insert, before update, before delete, after insert, after update, after delete, after undelete) {
new AccountTriggerHandler.execute();
}
@jongpie
jongpie / generate-sfdx-retrieve-commands.cls
Last active November 30, 2023 12:37
Generates sfdx commands to retrieve all Salesforce Reports & Dashboards (since wildcards are not supported)
// Get the reports & dashboards
List<Report> reports = [SELECT Id, DeveloperName, FolderName FROM Report ORDER BY FolderName, DeveloperName];
Set<String> folderNames = new Set<String>();
for (Report report : reports) {
folderNames.add(report.FolderName);
}
List<Dashboard> dashboards = [SELECT Id, DeveloperName, FolderName FROM Dashboard ORDER BY FolderName, DeveloperName];
for (Dashboard dashboard : dashboards) {
folderNames.add(dashboard.FolderName);
@jongpie
jongpie / delete-old-flow-versions.py
Created April 20, 2021 19:32
Mass delete Flow metadata
import subprocess, json, os, platform, sys, getopt
import xml.dom.minidom
API_VERSION = '49.0'
NAMESPACE = {
'salesforce' : 'http://soap.sforce.com/2006/04/metadata',
'xsi' : 'http://www.w3.org/2001/XMLSchema-instance'
}
@jongpie
jongpie / convert-dlrs-rules.cls
Last active April 26, 2021 22:14
Convert DLRS rules to Rollup rules
// This script converts any DLRS rules (stored in dlrs__LookupRollupSummary2__mdt) to Rollup__mdt records and deploys them to the current org
// Use the org defaults for all converted rules
static final RollupControl__mdt ROLLUP_CONTROL = [SELECT Id, DeveloperName FROM RollupControl__mdt WHERE DeveloperName = 'Org_Defaults'];
// Prepare the converted Rollup__mdt CMDT records for deployment
Metadata.DeployContainer deployment = new Metadata.DeployContainer();
for (dlrs__LookupRollupSummary2__mdt dlrsRule : dlrs__LookupRollupSummary2__mdt.getAll().values()) {
String customMetadataTypePrefix = Schema.Rollup__mdt.SObjectType.getDescribe().getName().replace('__mdt', '');
@jongpie
jongpie / generate-retrieve-commands.cls
Last active June 18, 2024 13:54
SFDX: Retrieve All EmailTemplates
// Get the email templates
Set<String> folderNames = new Set<String>();
List<EmailTemplate> emailTemplates = [SELECT Id, DeveloperName, FolderName FROM EmailTemplate ORDER BY FolderName, DeveloperName];
for (EmailTemplate emailTemplate : emailTemplates) {
folderNames.add(emailTemplate.FolderName);
}
// Get the folder dev names - this assumes the Folder.Name (display name) is unique in the org
Map<String, String> folderDisplayNameToDevName = new Map<String, String>();
for (Folder folder : [SELECT Id, DeveloperName, Name FROM Folder WHERE Name IN :folderNames and Name != 'Unfiled Public Classic Email Templates']) {
@jongpie
jongpie / FieldNamesScript.cls
Last active September 21, 2022 02:49 — forked from Feldstrom/LayoutDescriber.cls
Apex script for pulling field names from specific page layouts
public String objectName = ''; //example 'Case'
public String layoutName = ''; //example: 'Case Layout'
new LayoutDescriber().run(objectName, layoutName);
// In anonymous Apex, you can define & run a class.
// In this script, using a class ensures all describe methods work, regardless of field-level security (FLS)
public without sharing class LayoutDescriber {
public void run(String objectName, String layoutName) {
layoutName = objectName + '-' + layoutName;
@jongpie
jongpie / PackageSubscriberMetrics.cls
Created September 15, 2021 19:43
Package Subscriber Metrics
public class PackageSubscriberMetrics {
public class SubscriberOrgSummary {
public Id parentOrgId;
public String subscriberName;
public Boolean installedInParentOrg = false;
public Integer numberOfOrgs = 0;
public List<SubscriberOrgDetails> subscriberOrgDetails = new List<SubscriberOrgDetails>();
}
public class SubscriberOrgDetails {