Skip to content

Instantly share code, notes, and snippets.

View shanerk's full-sized avatar
Wizards only, fools!

Shane K shanerk

Wizards only, fools!
View GitHub Profile
@shanerk
shanerk / apex_debug_log_tail.sh
Last active May 10, 2024 17:39
Apex Debug Log Tail for VSCode
#!/bin/bash
# Execute this command in VSCode terminal. Your DEBUG logs will stream into the terminal from the org.
# Very useful to see DEBUG messages when running unit tests.
sf apex tail log --color | grep 'USER_DEBUG\|FATAL_ERROR'
@shanerk
shanerk / package.xml
Last active April 23, 2025 17:04
Salesforce package.xml file to get all metadata from your org. Works great with vscode and cli.
<?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>

Steps to Create DX Package Versions

Get Package Id

First you need the Package Id for your package. Package details can be obtained as follows:

sfdx force:package:version:report -p YOUR_PACKAGE_NAME

Ensure your sfdx-project.json has the Package ID and not the Subscriber Package Version Id set in this section:

@shanerk
shanerk / getChildRelations.cls
Created May 18, 2020 19:50
Gets list child relation API names based on the child object type (Salesforce Apex)
// Gets list child relation API names based on the child object type (Salesforce Apex)
//
DescribeSObjectResult type = SobjectType.Account;
String filter = 'Feed';
for (ChildRelationship relation : type.getChildRelationships()) {
if (String.valueOf(relation).contains(filter))
system.debug('* ' + relation.getChildSObject() + ' = ' + relation.getRelationshipName());
}
@shanerk
shanerk / get_mdt.sh
Created May 20, 2020 20:21
Pull down all custom metadata records for a Salesforce org and unpack them into the DX format
# Pull down all custom metadata records for a Salesforce org and unpack them into the DX format
# Run from the root of your Salesforce DX project, the script assumes that your project is a git repo
#!/bin/bash
mkdir .tmp
echo '<?xml version="1.0" encoding="UTF-8"?><Package xmlns="http://soap.sforce.com/2006/04/metadata"><types><name>CustomMetadata</name><members>*</members></types><version>41.0</version></Package>' > .tmp/package.xml
echo 'Retrieving metadata from Salesforce...'
sfdx force:mdapi:retrieve --retrievetargetdir .tmp/ --wait 5 --unpackaged .tmp/package.xml
@shanerk
shanerk / deploy.sh
Last active March 22, 2024 18:41
Deploy to Salesforce with GIT Changeset (-d flag runs against HEAD and default org with no confirmations)
#!/bin/bash
cleanExit() {
rm changes.txt*
exit
}
QUICK=false
while [[ $# -gt 0 ]]; do
Description:
These profiles are not supposed to be accessible as they are used for App Exchange packages.
When you go to the Package License Manager profile as an Org Admin, it tells you that you don't have sufficient privileges to change that profile.
But the page we really need to get to is the Profile Record Type edit page.
<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Default ruleset used by the CodeClimate Engine for Salesforce.com Apex" xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>Default ruleset used by the Code Climate Engine for Salesforce.com Apex</description>
<exclude-pattern>.*/.sfdx/.*</exclude-pattern>
<!-- COMPLEXITY
<rule ref="category/apex/design.xml/ExcessiveClassLength" message="Avoid really long classes (lines of code)">
<priority>3</priority>
<properties>
<property name="minimum" value="1000" />
</properties>
@shanerk
shanerk / clean_deleted_git_branches.sh
Last active March 18, 2024 19:25
Cleanup Local Branches which were deleted on the remote
git fetch -p
git for-each-ref --format '%(refname:short) %(upstream:track)' |
awk '$2 == "[gone]" {print $1}' |
xargs git branch -D
@shanerk
shanerk / diffclip.sh
Last active March 27, 2023 16:53
Git Diff to Clipboard
#Linux / OSX / ZSH
git diff main --name-status | pbcopy
#Windows Powershell
git diff main --name-status | scb
#Windows CMD
git diff main --name-status | clip