Skip to content

Instantly share code, notes, and snippets.

@jkentjnr
jkentjnr / delete_obsolete_flows.sh
Created October 3, 2024 23:07
Salesforce_Bash_Scripts
# https://salesforce.stackexchange.com/questions/275679/remove-all-old-flow-versions-using-sfdx
sfdx force:data:soql:query --query "SELECT Id FROM Flow WHERE Status = 'Obsolete'" --target-org $1 --use-tooling-api --result-format csv > flowTodelete.csv
while read c; do
if [[ "$c" != "Id" && "$c" != "Your query returned no results." ]]
then
sfdx force:data:record:delete --sobject Flow --record-id $c --target-org $1 --use-tooling-api
fi
done < flowTodelete.csv
@jkentjnr
jkentjnr / convert.apex
Created October 19, 2023 11:01
Salesforce_Lead_Convert
// Set lead Id here.
Id leadId = '00Q8t0000024px3EAA';
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted = true LIMIT 1];
String leadStatus = convertStatus.MasterLabel;
// Execute Salesforce' lead convert service
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(leadId);
lc.setConvertedStatus(leadStatus);
@jkentjnr
jkentjnr / copy_between_orgs.sh
Created April 6, 2023 04:55
Salesforce: Publish Between Orgs using SFDX
sfdx alias set [email protected]
sfdx force auth web login -a abc_production
sfdx alias set [email protected]
sfdx force auth web login -a xyz_sandbox -r https://xyzfoundation--movedata.sandbox.my.salesforce.com
sfdx force:mdapi:retrieve -k package.xml -s -r . -u abc_production
unzip ./unpackaged.zip -d ./unpackaged
sfdx force:mdapi:deploy -d ./unpackaged -w 10 -u xyz_sandbox
@jkentjnr
jkentjnr / DDMMYYY_to_Date.txt
Last active April 16, 2024 04:35
Bespoke Salesforce Formulas
DATE(
VALUE(RIGHT({!InvoiceDate}, 4)),
VALUE(
MID(
{!InvoiceDate},
FIND("/", {!InvoiceDate}) + 1,
FIND("/", {!InvoiceDate}, (FIND("/", {!InvoiceDate}) + 1)) - FIND("/", {!InvoiceDate}) - 1
)
),
VALUE(LEFT({!InvoiceDate}, FIND("/", {!InvoiceDate}) - 1))
@jkentjnr
jkentjnr / sfdx-deploy.yaml
Created November 21, 2022 09:21
Azure DevOps Pipeline Template for Salesforce DX Sandbox Deployment
# ----------------------------------------------------------------------------------------------------
# SFDX Deploy
# ----------------------------------------------------------------------------------------------------
parameters:
pool: {}
jobs:
- deployment: sfdx_deploy
displayName: SFDX Deploy
@jkentjnr
jkentjnr / clean.apex
Last active February 15, 2023 04:25
Clean out MD Development Environments
delete [SELECT Id FROM Opportunity LIMIT 2000];
delete [SELECT Id FROM npe03__Recurring_Donation__c LIMIT 2000];
delete [SELECT Id FROM Case LIMIT 2000];
delete [SELECT Id FROM Contact LIMIT 2000];
delete [SELECT Id FROM Account LIMIT 2000];
delete [SELECT Id FROM md_npsp_pack__Platform_Key__c LIMIT 2000];
delete [SELECT Id FROM md_forms_pack__Contact_Platform_Key__c LIMIT 2000];
delete [SELECT Id FROM md_forms_pack__Account_Platform_Key__c LIMIT 2000];
delete [SELECT Id FROM Campaign LIMIT 2000];
delete [SELECT Id FROM md_npsp_pack__Question_Response__c LIMIT 2000];
@jkentjnr
jkentjnr / ContactDuplicateRule.txt
Last active August 16, 2022 11:42
Duplicate Detection via Apex
Rule Name: MoveData Contact Duplicate
Rule Order: 3 of 3
Object: Contact
Record-Level Security: Enforce sharing rules
Action On Create: Allow
Operations On Create: Alert / Report
Action On Edit: Allow
Operations On Edit: Alert / Report
Alert Text: Use one of these records?
Active; Checked
resource "aws_api_gateway_method" "graphRoot" {
rest_api_id = aws_api_gateway_rest_api.api.id
resource_id = aws_api_gateway_resource.graphRoot.id
http_method = "POST"
authorization = "COGNITO_USER_POOLS"
authorizer_id = aws_api_gateway_authorizer.cognito.id
}
resource "aws_api_gateway_integration" "graphRoot" {
rest_api_id = aws_api_gateway_rest_api.api.id
@jkentjnr
jkentjnr / graphBuilder.apex
Created October 14, 2019 12:38
Graphql Builder for Salesforce Apex
public class GraphBuilder {
/*
EXAMPLE
-------
String q = new GraphBuilder.QueryOperation(
new GraphBuilder.QueryResolver(
'notification',
@jkentjnr
jkentjnr / README.md
Last active May 14, 2019 11:56
Campaign Setup Steps

Grassrootz Setup Steps


  • Create a campaign at Grassrootz

This will ensure the campaign is pushed to Salesforce. At this point, you will need to configure your campaign. Navigate to the newly created campaign in Salesforce.

  • Rename the campaign if so desired.
  • Configure the Start and End dates for the Campaign