Skip to content

Instantly share code, notes, and snippets.

View martyychang's full-sized avatar

Marty Chang martyychang

View GitHub Profile
@martyychang
martyychang / .bash_profile
Created October 29, 2018 12:29
Better Git integration with Terminal on Mac OS X
# Git shell
# https://gist.github.com/trey/2722934
source /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash
source /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=true
GIT_PS1_SHOWCOLORHINTS=true
export PS1='\[\033[0;36m\]\u@\h\[\033[0;35m\]:\[\033[0;33m\]\w\[\033[0;37m\]$(__git_ps1)\[\033[0m\]\n\$ '
@martyychang
martyychang / listObjectFields.java
Last active October 8, 2018 19:13
Generate a list of all fields and data types for a given object and send the metadata in CSV format via email
// README: This is the only line you need to edit (generally speaking)
// This is the object for which I want to extract the field describes.
// Running this script will send the resulting field list to your user's email,
// with the fields as an attached CSV file.
Schema.DescribeSObjectResult objectDescribe = Schema.SObjectType.OpportunityLineItem;
/**
* Wrapper class to return CSV rows
*/
public class FieldCsvWriter {
@martyychang
martyychang / S1Reporting.cls
Last active May 26, 2018 15:41
Demonstration of using Apex as a conduit for accessing the Salesforce1 Reporting REST API in Lightning
public class S1Reporting {
/*
* @see Salesforce1 Reporting REST API Developer Guide
*/
public class GetAnalyticsReportsResponseBody {
@AuraEnabled
public String name;
@martyychang
martyychang / DependentPicklistDemoController.cls
Last active September 27, 2017 03:11
Demonstration of how to configure dependent picklists in Lightning on the Salesforce1 Platform, using features currently available in the Winter '15 beta
public class DependentPicklistDemoController {
@AuraEnabled
public static List<Contact> getContacts() {
return [
SELECT Id, Name, AccountId, Account.Name
FROM Contact
LIMIT 200
];
}
@martyychang
martyychang / .gitignore
Created July 17, 2017 12:26
MavensMate project init
# MavensMate
config/
# Sublime Text
*.sublime*
@martyychang
martyychang / CommunityTopicListItemController.cls
Created April 18, 2017 21:45
Server-side controller for Lightning component enabling partner users to follow and unfollow topics
public class CommunityTopicListItemController {
@AuraEnabled
public static void subscribe(Id entityId) {
ConnectApi.Subscription subscription =
ConnectApi.ChatterUsers.follow(Network.getNetworkId(), 'me', entityId);
}
@AuraEnabled
public static void unsubscribe(Id subscriptionId) {
@martyychang
martyychang / is-salesforce1.js
Created September 25, 2014 12:40
isSalesforce1() JavaScript function
/*
* @return whether JavaScript is executing
* within the context of Salesforce1.
* If not, the context is assumed
* to be the regular browser "app".
*/
function isSalesforce1() {
// Use the presence of sforce.one
// as the acid test to know that
@martyychang
martyychang / AdvertiserListingTaskService.java
Created May 24, 2016 19:11
How to map task names to task services
@Service
public class AdvertiserListingTaskService {
public void executeWithConfig(TaskConfig config) {
AdvertiserListingTask task = getTask();
task.apply(config);
task.run(); // Or something like executor.execute(task)
}
@Lookup
@martyychang
martyychang / OneLeadController.cls
Last active May 16, 2016 16:51
Why does passing an array of Lead objects to an Apex controller action cause an "internal salesforce.com error"?
public class OneLeadController {
@AuraEnabled
public static Id createLead(Lead newLead) {
insert newLead;
return newLead.Id;
}
@AuraEnabled
public static List<Id> createLeads(List<Lead> newLeads) {
@martyychang
martyychang / IntegrationService.java
Last active April 26, 2016 12:01
Unsure whether using `ObjectFactory` is the best way to get a new prototype bean.
@Service
public class IntegrationService {
@Autowired
private TaskExecutor integrationTaskExecutor;
@Autowired
private IntegrationTaskFactory integrationTaskFactory;
/**