Skip to content

Instantly share code, notes, and snippets.

View b-wilder's full-sized avatar

Brock Elgart b-wilder

  • Steampunk
  • Hopedale, MA
View GitHub Profile
@b-wilder
b-wilder / gist:0cd489bd8f1025be6068
Last active August 29, 2015 14:17
Get all creatable fields for any SObject (Apex, Salesforce)
public static set<string> getCreatableFields(Schema.SObjectType objectType)
{
Map<String, Schema.SObjectField> fMap = objectType.getDescribe().Fields.getMap();
set<string> creatableFields = new set<string>();
if (fMap != null){
for (Schema.SObjectField ft : fMap.values()){ // loop through all field tokens (ft)
Schema.DescribeFieldResult fd = ft.getDescribe(); // describe each field (fd)
if (fd.isUpdateable()&&!fd.isUnique()){ // field is creatable
creatableFields.add(fd.getName());
@b-wilder
b-wilder / ProductionCode.cls
Created April 19, 2019 13:23
Simulating date/time in apex for accurate, time-based testing
public with sharing class ProductionCode.cls {
...
private static void scheduleBatchExecution(){
...
//Use in place of DateTime.now()
DateTime nowDT = Utilities.getCurrentDateTime();
@b-wilder
b-wilder / sfRelease.ps1
Last active February 12, 2022 15:58
Deploy only the deltas
#Azure DevOps / Powershell example
$priorVersionNumber = $args[0] #Assumption: you have the version number the prior deployment to this environment was tagged with
$newVersionNumber = $args[1] #Assumption: you have the new version number to tag the new commit with
$environment = $args[2] #Assumption: you have the name of the environment you are deploying to
$releaseCommit = $args[3] #Assumption: you have the id of the commit you are deploying
Invoke-Expression "git checkout $releaseCommit"
#Use the SFDX Git Delta plugin to deploy the delta between the checked out release commit and the tag last deployed to the current environment
#https://www.npmjs.com/package/sfdx-git-delta
@b-wilder
b-wilder / scripts\ps\executeApexScripts.ps1
Created January 22, 2022 16:54
Execute all apex scripts in a folder
#Loop through all .apex scripts in the directory passed to $args[0] and execute them in sequence
$path = $args[0]
Get-ChildItem $path -Filter *.apex |
Foreach-Object {
# $_ : object in loop
# $_.FullName: full path to file, including extension
# $fileName: filename and extension without path
$fileName = Split-Path -Path $_.FullName -Leaf -Resolve
sfdx force:apex:execute -f "$path\$fileName"
}