Skip to content

Instantly share code, notes, and snippets.

View amphro's full-sized avatar

Thomas Dvornik amphro

View GitHub Profile
@amphro
amphro / get-package-dir-deploy-order.ts
Created August 28, 2020 18:58
Figures out the deploy order given a sfdx-project.json.
import { ensure } from '@salesforce/ts-types';
import { NamedPackageDir, SfdxError, SfdxProject } from '@salesforce/core';
const project = SfdxProject.getInstance();
const pkgDirs = project.getUniquePackageDirectories();
const pkgAliases = Object.keys(project.getSfdxProjectJson().getContents().packageAliases || {});
class PkgDirNode {
public pkgDir: NamedPackageDir;
@amphro
amphro / listprojectorgs.js
Created December 19, 2017 16:08
SFDX List Project Orgs
const exec = require('child_process').execSync;
let lines = exec('sfdx force:org:list --all').toString().split(/\n/);
let index;
// Skip the non-scratch orgs
for (var i in lines) {
if (lines[i].toString().match(/.*SCRATCH ORG NAME.*/)) {
index = i;
break;
@amphro
amphro / case-convert
Last active June 3, 2017 00:45
Utility for converting JSON files to heads down camel case
#/usr/bin/env bash
##
# Utility for converting json files to heads down camel case
##
if [[ $1 == "help" || $1 == "--help" ]]
then
echo "Usage: case-convert [help] path
@amphro
amphro / sfdx-push-recordtypes
Created May 5, 2017 21:17
Push RecordTypes and Data using SFDX
### Setup Import File and Permission Set
# Step 1. Export the RecordTypes
-> sfdx force:data:tree:export -q "SELECT ID, Name, DeveloperName, SobjectType FROM RecordType" -o data
Wrote 1 records to data/RecordType.json
# Here is what the export might look like
-> more data/RecordType.json
{
@amphro
amphro / DisableAutoCloseOnVFEditors
Last active August 29, 2015 14:04
A bookmarklet to remove autoCloseTags on existing VF editors and all plugins on new VF editos.
javascript:
console.log('Disabling auto close tags on all existing vf editors');
Ext.getCmp('editors').items.each(function(editor) {
if (editor instanceof apex.editor.VisualforceEditor && editor.cmEditor) {
editor.cmEditor.codeEditor.setOption('autoCloseTags', false);
console.log('Removed autoclose on editor ' + editor.id);
}
});
@amphro
amphro / DeleteLogsWithNullLogUsers.js
Created December 11, 2013 18:26
Delete ApexLogs where the LogUser returns null, causing a JS error. Run this in the browsers javascript console when on the Developer Console
SfdcDevConsole.ToolingAPI.query('SELECT Id, LogUserId, LogUser.Name FROM ApexLog', {
continuation : function(response) {
var records = response.records;
console.log('Found ' + records.length + ' log(s)');
var idsToDelete = [];
for (var i = 0; i < records.length; i++) {
var rec = records[i];
console.log('\t' + rec.Id + ' ' + rec.LogUserId);
if (!rec.LogUser || rec.LogUser === 'null') {
idsToDelete.push(rec.Id);
@amphro
amphro / RunNSTestsRaw.js
Created December 11, 2013 00:46
Run an org's namespace tests from JS (untested). NOTE: This only works with v30.0.
//This example assumes you have a sendRequest method, that can send an AJAX call to Salesforce with Auth header all set up
function runNamespacedTest(namespace) {
function getTestIdsFromApexClasses(classes) {
var ids = [];
for (var i = 0; i < classes.length; i++) {
var rec = classes[i];
var st = rec.SymbolTable;
var mods = st.tableDeclaration.modifiers;
@amphro
amphro / RunNSTest.java
Created December 11, 2013 00:45
Run an org's namespace tests from SOAP (untested). NOTE: This only works with v30.0. To work with v29.0, you must use the Apex API (wsdl).
SoapConnection conn = // Get the tooling soap connection;
String namespace = "";
QueryResult qr = conn.query("SELECT Id, SymbolTable FROM ApexClass WHERE NamespacePrefix = '"+namespace+"'");
List<String> ids = new ArrayList<String>();
SObject[] classes = qr.getRecords();
for (int i = 0; i < classes.length; i++) {
ApexClass rec = (ApexClass)classes[i];
@amphro
amphro / RunNSTestBookmarklet.js
Last active December 30, 2015 23:49
A bookmarklet to run an org's namespace tests from the Developer Console To add a bookmarklet, go to the bookmark manager, add a new bookmark with a name of "Run NS Tests" and the following code as the URL. Then, open the Developer Console in a tab and click on the bookmarklet. The uncompressed code is here: https://gist.github.com/amphro/7903051
javascript:function runNamespacedTest(e){function r(e){if(console&&console.log)console.log(e)}function i(){Ext.Msg.alert("Running namespaced tests failed","Please look at the javascript console for more information.")}function s(e){if(e.length===0){Ext.Msg.alert("No tests enqueued",'No test found in namespace "'+n+'"');return}r("Enqueuing "+e.length+" tests");Ext.Msg.updateProgress(.6,"Enqueuing "+e.length+" tests");if(SfdcDevConsole.ToolingAPI.runTests){SfdcDevConsole.ToolingAPI.runTests({classids:e},{continuation:function(){Ext.Msg.close()},failure:i})}else{Ext.Ajax.request({url:"/_ui/common/apex/test/ApexTestQueueServlet",params:{action:"ENQUEUE",classid:e},success:function(){Ext.Msg.close()}})}}function o(e){var t=[];for(var n=0;n<e.length;n++){var i=e[n];var s=i.SymbolTable;var o=s.tableDeclaration.modifiers;var u=o.length;while(u--){if(o[u]==="TEST"){r("Found test: "+s.name);t.push(i.Id)}}}return t}function u(){SfdcDevConsole.ToolingAPI.query("SELECT Id, SymbolTable FROM ApexClass WHERE NamespacePrefix
@amphro
amphro / RunNSTests.js
Last active December 30, 2015 23:49
Run an org's namespace tests from the developer console. Just open the browser's Javascript console and past the code in. Update: Will now use an unsupported servlet instead of the Tooling API to prevent compilation if the SymbolTables are not in the cache. To use the Tooling API, change line 115/116.
function runNamespacedTest(namespace) {
var thisOrgsNs = SfdcDevConsole.hasNamespace() ? SfdcDevConsole.namespace : '';
var ns = namespace || thisOrgsNs;
function log(msg) {
if (console && console.log) console.log(msg);
}
function showErrorMessage() {
Ext.Msg.alert('Running namespaced tests failed', 'Please look at the javascript console for more information.');