Skip to content

Instantly share code, notes, and snippets.

View rtanikella's full-sized avatar

Raj Tanikella rtanikella

  • Salesforce.com
  • USA
View GitHub Profile
@rtanikella
rtanikella / SOQL for Object and Field Access.md
Last active May 22, 2023 15:40
SOQL queries to get field access permissions from a Salesforce org.

Object Access

Get CRUD perms on objects given a set of profiles. This list of objects here is the set of QualifiedApiNames of all Licensed Custom Objects delivered by Salesforce CPQ and Advanced Approvals packages.

SELECT
  SobjectType,
  Parent.Profile.Name,
  PermissionsCreate,
  PermissionsRead, 
  PermissionsEdit, 
  PermissionsDelete, 
@rtanikella
rtanikella / getCreateableFieldsQuery.zsh
Created March 15, 2023 03:03
Retrieves the schema description of a Salesforce sobject and emits a SOQL query listing only the fields that are 'createable=true'.
#!zsh
if [ ! -n "$2" ]
then
help_text=$( cat <<ENDxxx
$0 allows you to specify a Salesforce object defined within
an org and returns a SOQL query that returns only the createable
fields of that object. Use this query to quickly extract a CSV
of the fields of that object that you can insert or upsert to
an org without having to determine which fields will fail because
@rtanikella
rtanikella / wakehist.sh
Created December 17, 2022 15:24
A shell script to list events in the macOS to list out sleep and wake events. This might be out-of-date with current versions of macOS (Monterrey/12.6.1)
#!/bin/sh
log show --last 24h | grep -e "System Sleep" -e " Wake reason" > /tmp/sleep-wake-hist.txt
pmset -g log | grep -e " Sleep " -e " Wake " >> /tmp/sleep-wake-hist.txt
sort -o /tmp/sleep-wake-hist-sorted.txt /tmp/sleep-wake-hist.txt
echo -n `wc -l /tmp/sleep-wake-hist-sorted.txt` log lines found

Given the Salesforce standard way of textually representing dates (YYYY-MM-DDTHH:mm:ss.zzzZ, for example 2018-11-19T16:06:21.000Z), the following Excel formulae will help you parse out components: Assuming B2 is the cell in which the Salesfore date is entered

  • Year: =LEFT(B2,4)
  • Month: =RIGHT(LEFT(B2,7),2)
  • Day: =RIGHT(LEFT(B2,10),2)
  • Hour: =RIGHT(LEFT(B2,10),2)
  • Min: =RIGHT(LEFT(B2,10),2)
  • Sec: =RIGHT(LEFT(B2,19),2)
  • Timezone: =RIGHT(B2,4)
  • Excel-native number that represents the date in Microsoft Excel date-time code:
@rtanikella
rtanikella / ka-replace.sh
Last active November 9, 2018 19:35
Use this to search and replace text within Classic Salesforce Knowledge Articles. It is globally replaces a string using a perl regular expression and writes to STDOUT only those articles that have been changed.
#!/bin/bash
if [ ! -n "$1" ]
then
help_text=$( cat <<ENDxxx
Use this to search and replace text within Classic Salesforce Knowledge
Articles. It is globally replaces a string using a perl regular expression
and writes to STDOUT only those articles that have been changed.
Usage: $0 "/search/replace-regexp/" input-file.csv [prefix] [--debug]
#!/bin/bash
if [ ! -n "$1" ]
then
help_text=$( cat <<ENDxxx
Use this to adjust the URLs of links within Classic Salesforce Knowledge
Articles to reference the destination Salesforce instance instead of the
source instance.
Usage: $0 input-file.csv prefix
@rtanikella
rtanikella / KAT2A.sh
Last active November 9, 2018 17:35
Adjust for a change in the article type of Classic Salesforce Knowledge Articles: This script adjusts the URLs of links within Classic Salesforce Knowledge Articles that reference other such articles to use an article type of 'Article' instead of 'Knowledge_Article_Type'
#!/bin/bash
if [ ! -n "$1" ]
then
multi_line_var=$( cat <<ENDxxx
Use this to adjust the URLs of links within Classic Salesforce Knowledge
Articles to use an article type of 'Article' instead of
'Knowledge_Article_Type'
Usage: KAT2A.sh input-file.csv
@rtanikella
rtanikella / Counting occurrences with grep.md
Created June 23, 2018 19:06
How to use grep and wc to count the number of occurrences of a string in a file, even when there are multiple occurrences of the string in a single line.
@rtanikella
rtanikella / Importing Knowledge Articles.md
Last active November 9, 2018 17:37
Describes my process of dealing with Classic Salesforce Knowledge Articles to export from one Salesforce org and import to another. In this description "NA33" is the source org and "NA35" is the target org.

Problem: To determine which Knowledge Articles in NA33 contain embedded images (<img). Of these, some will reference an opaque Salesforce URL because those images were directly pasted into the Salesforce Knowledge Article Rich Text Editor; others will not. Those that contain no IMGs can be processed with an ETL tool to migrate them from NA33 to NA35. This with IMGs will need to further be divided into those that have Salesforce opaque image URLs and those that have other URLs (either publicly available ones or ones that were not adequatly captured when the original curation took place during TSA12.)

Solution: Extract the IDs and corresponding articles in a way that makes it easy to search the article for IMG tags and know the article's ID when a match is found. In the procedure listed here, the way to do this is to ensure that each article is entirely on a single line.

Prerequisites and Tools This process will require the following:

  • Bash shell (such as Git Bash or Cygwin)
  • perl installed in the Bas
@rtanikella
rtanikella / Decoding URIs in Node.js
Created November 16, 2016 20:58
A one-liner to decode a URI in Node.js (I use this in REPL mode)
// Note that in Node.js REPL mode the ':' and ',' are not decoded by decodeURI(). Hence the regexes.
decodeURI("Text to decode").replace(/%2C/g,",").replace(/%3A/g,":");