Skip to content

Instantly share code, notes, and snippets.

View martyychang's full-sized avatar

Marty Chang martyychang

View GitHub Profile
User Event Type Constant User Event Type Value Entry Point Handler Method Name
CREATE create beforeSubmit() createBeforeSubmit()
EDIT edit beforeSubmit() editBeforeSubmit()
XEDIT xedit afterSubmit() xeditAfterSubmit()
@martyychang
martyychang / CommunityUserPhotoUpload.component
Last active May 12, 2022 19:43
Visualforce component demonstrating the use of ConnectApi to upload Chatter profile photo
<apex:component selfClosing="true"
controller="CommunityUserPhotoUploadController"
allowDML="true">
<apex:attribute name="subject" type="Id"
assignTo="{!userId}"
required="true"
description="The User ID for the community user"/>
<apex:form>
<apex:image value="{!largePhotoUrl}"/>
@martyychang
martyychang / beautifyDealhub.js
Created August 24, 2021 00:11
Make the DealHub.io interface more developer-friendly for editing conditional answers and other attributes.
var sheets = document.styleSheets;
var neatSheet = null;
/* Find the default style to edit */
for (i = 0; i < sheets.length; i++) {
if (sheets[i].title === null) {
neatSheet = sheets[i];
}
}
@martyychang
martyychang / batch-create-records.js
Created January 24, 2020 16:28
Expected input objects for Salesforce "batch create records" and "batch update records" actions in Tray.io
// You can reference the input variables using input.NAME
exports.step = function(input) {
return _.map(input.rows, function(row) {
// Please note that the format of this object is different
// from the format for the "Batch update records" operation.
return [
{
"key": "Role__c",
"value": row.role
@martyychang
martyychang / ActionSupportParamDemo.page
Created December 12, 2014 15:44
Demonstration of how apex:actionSupport and apex:param are supposed to work together
<apex:page controller="ActionSupportParamDemoController">
<apex:form>
<apex:repeat value="{!accounts}" var="account">
<apex:inputCheckbox value="{!account.IsActive__c}">
<apex:actionSupport event="onchange"
action="{!handleAccountCheckboxChange}">
<apex:param id="account" name="accountId" value="{!account.Id}"
assignTo="{!targetAccountId}"/>
</apex:actionSupport>
</apex:inputCheckbox>
@martyychang
martyychang / STRUCTURE.md
Last active March 4, 2021 08:29
Suggested directory structure for a web API project, written in Python

api/

Handlers, etc. Everything needed to translate a web request into data that can be passed into a regular Python function and vice versa.

api/exports.py

Typically this would be imported into an app like this.

@martyychang
martyychang / SobjectQueryGenerator.cls
Last active October 5, 2020 14:22
Generate Salesforce SELECT * query, Postgres CREATE TABLE statement and database-conf.xml content for a given object.
public class SobjectQueryGenerator {
private List<Schema.DescribeFieldResult> fieldDescList;
private Schema.DescribeSObjectResult sobjectDesc;
public SobjectQueryGenerator(Schema.DescribeSObjectResult sobjectDesc, Boolean includeCalculated) {
this.sobjectDesc = sobjectDesc;
this.fieldDescList = new List<Schema.DescribeFieldResult>();
for (Schema.SObjectField eachField : this.sobjectDesc.fields.getMap().values()) {
Schema.DescribeFieldResult eachDfr = eachField.getDescribe();
@martyychang
martyychang / combine_csv.py
Created August 23, 2020 19:24
Combine multiple CSV files into a single CSV file
# https://blog.softhints.com/how-to-merge-multiple-csv-files-with-python/
# https://www.techbeamers.com/pandas-merge-csv-files/
import os, glob
import pandas as pdlib
path = "/Users/mchang/Desktop/Salesforce/Account/1598097614646/"
list_of_files = glob.glob(os.path.join(path, "data_*.csv"))
# Consolidate all CSV files into one object
result_obj = pdlib.concat([pdlib.read_csv(file) for file in list_of_files])
@martyychang
martyychang / listsobjectfields.py
Created January 31, 2020 17:40
List all field labels and field names for an object
import csv
import os
import xml.etree.ElementTree as ET
FIELDS_SUBDIR = 'fields'
METADATA_NAMESPACE = 'http://soap.sforce.com/2006/04/metadata'
OBJECTS_DIR = 'force-app/main/default/objects'
namespaces = {
'': METADATA_NAMESPACE
@martyychang
martyychang / check.sh
Last active December 28, 2018 14:01
Trailblazer .bin
# Check to require a username to be [given as argument][1]
#
# [1]: https://stackoverflow.com/questions/6482377/check-existence-of-input-argument-in-a-bash-shell-script
if [ -z "$1" ]; then
echo ERROR: Username argument required!
# [terminate and indicate error][3]
#
# [3]: https://stackoverflow.com/questions/4381618/exit-a-script-on-error
exit 1