-
Notifications
You must be signed in to change notification settings - Fork 4
/
.salesforcerc
185 lines (160 loc) · 7.12 KB
/
.salesforcerc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
# Export a function as an entry point to PMD (which we use for Apex linting).
# This lets us call "apexpmd" from child processes, like npm scripts
function apexpmd() {
/usr/local/Cellar/pmd/6.16.0/libexec/bin/run.sh pmd "$@"
}
export -f apexpmd
# 1 salesforci boi
# Find the value of any custom labels on a system matching a search pattern
lbl() {
if [[ -z "$1" ]] || [[ -z "$2" ]]; then
echo "Usage: lbl [ORG_ID] [LABEL_REGEX]"
return 1
fi
local result
result=$(sfdx force:mdapi:listmetadata -m CustomLabel -u "${1}" --json)
# shellcheck disable=SC2181
if [ $? -ne 0 ];
then
>&2 echo "Error!"
>&2 echo "${result}"
else
>&2 echo "All labels on ${1} matching '${2}' (case insensitive):"
echo "${result}" | jq -r '.result[] | select(.fullName|test("'"${2}"'"; "i")) | .fullName' | while read -r line ; do
stmt "${1}" "'${line}: ' + Label.${line}" quiet
done
fi
}
# Execute an apex expression against an environment
exp() {
if [[ -z "$1" ]] || [[ -z "$2" ]]; then
echo
echo "${BOLD}NAME:${COLOR_RESET} exp"
echo
echo "${BOLD}DESCRIPTION:${COLOR_RESET} Execute an expression, and print the output. Takes the apex expression you pass in and wraps it in a System.debug() call.${COLOR_RESET}"
echo
echo "${BOLD}USAGE:${COLOR_RESET} exp [ORG_ID] [EXPRESSION_TO_EVALUATE] ['quiet' | 'q']"
echo "Pass quiet or q as the last paremeter to supress notification messages"
echo
echo "${COLOR_RED}Error: ${COLOR_RESET} Expected two arguments to exp, the org ID and the expression."
return 1
fi
local apexCommand
apexCommand='System.debug('"${2}"');'
if [ "$3" != "quiet" ] && [ "$3" != "q" ]; then
>&2 echo "${COLOR_BLUE}${BOLD}Executing against ${COLOR_PURPLE}${BOLD}${1}${COLOR_BLUE}:${COLOR_RESET}"
>&2 echo "${COLOR_BLUE}${apexCommand}${COLOR_RESET}"
>&2 echo
fi
# Example apex output, to see what we're grepping for. Logs for the
# multline command System.debug('a\nb'):
# 11:38:56.11 (11521203)|EXECUTION_STARTED
# 11:38:56.11 (11525424)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
# 11:38:56.11 (11944606)|USER_DEBUG|[1]|DEBUG|a
# b
# 11:38:56.11 (11980694)|CUMULATIVE_LIMIT_USAGE
# 11:38:56.11 (11980694)|LIMIT_USAGE_FOR_NS|(default)|
# We need to find from the start of USER_DEBUG to the next non-debug line.
# Notice "b" is put on a line by itself, making it tricky to include in output
sfdx force:apex:execute -u "${1}" -f /dev/stdin<<<"$apexCommand" | # Execute the expression inside a system.debug(). execute expects a file, so use <<< trick to make it seem like a file
pcregrep -M 'USER_DEBUG(.|\n)+?([\d]{2}:[\d]{2}:[\d]{2})' | # find debug line, and try to search up to the next apex ouptut line, starting with dd:dd:dd
sed '$d' | # remove the last line, which is the first non-debug line
sed 's/.*\|//' # find everything after the last pipe, which will be the debugged output
}
# Execute an apex expression against an environment
stmt() {
if [[ -z "$1" ]] || [[ -z "$2" ]]; then
echo
echo "${BOLD}NAME:${COLOR_RESET} stmt"
echo
echo "${BOLD}DESCRIPTION:${COLOR_RESET} Execute a statement or list of statements.${COLOR_RESET}"
echo
echo "${BOLD}USAGE:${COLOR_RESET} stmt [ORG_ID] [STATEMENTS_TO_EVALUATE] ['quiet' | 'q']"
echo "Pass quiet or q as the last paremeter to supress notification messages"
echo
echo "${COLOR_RED}Error: ${COLOR_RESET} Expected two arguments to stmt, the org ID and the statements."
return 1
fi
local apexCommand
apexCommand=${2}
if [ "$3" != "quiet" ] && [ "$3" != "q" ]; then
>&2 echo "${COLOR_BLUE}${BOLD}Executing against ${COLOR_PURPLE}${BOLD}${1}${COLOR_BLUE}:${COLOR_RESET}"
>&2 echo "${COLOR_BLUE}${apexCommand}${COLOR_RESET}"
>&2 echo
fi
# Example apex output, to see what we're grepping for. Logs for the
# multline command System.debug('a\nb'):
# 11:38:56.11 (11521203)|EXECUTION_STARTED
# 11:38:56.11 (11525424)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
# 11:38:56.11 (11944606)|USER_DEBUG|[1]|DEBUG|a
# b
# 11:38:56.11 (11980694)|CUMULATIVE_LIMIT_USAGE
# 11:38:56.11 (11980694)|LIMIT_USAGE_FOR_NS|(default)|
# We need to find from the start of USER_DEBUG to the next non-debug line.
# Notice "b" is put on a line by itself, making it tricky to include in output
sfdx force:apex:execute -u "${1}" -f /dev/stdin<<<"$apexCommand" # Execute the statement inside a system.debug(). execute expects a file, so use <<< trick to make it seem like a file
}
# TODO doesn't do anything, was editing string thing below and might have to
# build a dynamic soql query to do it
dumpsinmytruck() {
read -r -d '' VAR << EOM
String ((Id)'${2}').getSObjectType().getDescribe().getName()
List<Map<String, String>> lstfieldname = new List<Map<String, String>>();
Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Map <String, Schema.SObjectField> fieldMap = schemaMap.get('Task').getDescribe().fields.getMap();
for(Schema.SObjectField sfield : fieldMap.Values()) {
schema.describefieldresult dfield = sfield.getDescribe();
Map<String, String> field = new Map<String, String>();
field.put(
dfield.getName(),
dfield.getType() + ' : ' + dfield.getLabel()
);
lstfieldname.add(field);
}
System.debug('lstfieldname');
System.debug(lstfieldname);
EOM
}
alias orgls='open https://grhc.lightning.force.com/lightning/setup/DataManagementCreateTestInstance/home'
alias orgids='open https://grhc.lightning.force.com/lightning/setup/DataManagementCreateTestInstance/home'
function orgid() {
exp "$1" 'UserInfo.getOrganizationId()'
}
function custbyjarvisid() {
local comd
if [[ -n "$2" ]]; then
comd="[SELECT Id, Name FROM Account WHERE Customer_Account_ID__c = $2]"
fi
exp "$1" "$comd"
}
function whodat() {
exp "$1" "[SELECT username FROM User WHERE Id = '$2']"
}
function soqldev() {
exp AndrewDev "[$1]"
}
function whatis() {
exp $1 "((Id)'${2}').getSObjectType().getDescribe().getName()"
}
declare -a INSTANCE_URLS
INSTANCE_URLS[UAT]='https://grhc--uat.lightning.force.com'
INSTANCE_URLS[AndrewDev]='https://grhc--andrewdev.lightning.force.com'
# shellcheck disable=SC2034
INSTANCE_URLS[Unused]='' # Used for shellcheck disable above :(
function deploy_status() {
open "${INSTANCE_URLS[$1]}/lightning/setup/DeployStatus/home"
}
function trace_flags() {
open "${INSTANCE_URLS[$1]}/lightning/setup/ApexDebugLogs/home"
}
alias dstatus='deploy_status UAT'
alias tstatus='deploy_status AndrewDev'
alias tflags='trace_flags AndrewDev'
function lt() {
>&2 echo "${BOLD}Tailing ${COLOR_BLUE}${BOLD}${1} ${COLOR_RESET}${BOLD}logs...${COLOR_RESET}"
sfdx force:apex:log:tail -u "$1" | grep --color=always -E 'USER_DEBUG|ERROR'
}
function my_user_id() {
exp AndrewDev "[SELECT Id FROM User WHERE Email = '[email protected]']"
}