Skip to content

Instantly share code, notes, and snippets.

View martyychang's full-sized avatar

Marty Chang martyychang

View GitHub Profile
@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 / 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 / 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 / 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;
/**
@Configuration
public class AppConfig {
public @Bean Foo fooer() {
return new Foo("fooer");
}
public @Bean Foo fooey() {
return new Foo("fooey");
}
public class SimpleDomain {
ObjectId _id;
String code;
int numberOfUses;
}
@martyychang
martyychang / RegexScript.java
Created March 12, 2016 04:34
Java 7 script showing how a regex can be used to split strings delimited by backslash characters.
package script;
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
@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 / HiddenInputSupportDemo.page
Created December 11, 2014 03:45
Demonstration of using an apex:actionSupport with a "hidden" input
<apex:page standardController="Account">
<h2>Form</h2>
<apex:form>
<apex:inputText id="accountNameInput" styleClass="with-hidden"/>
<apex:inputText id="accountNameInputHidden"
value="{!Account.Name}"
style="display:none">
<apex:actionSupport event="onchange" action="{!quicksave}"
reRender="accountNameOutput"
status="accountNameStatus"/>
@martyychang
martyychang / SetNewOwner.trigger
Last active December 20, 2015 23:09
Trigger to enable users to change the Case Owner through a proxy field via a publisher action in Salesforce1
trigger SetNewOwner on Case (before insert, before update) {
for (Case eachCase : Trigger.new) {
if (eachCase.NewOwner__c != null) {
eachCase.OwnerId = eachCase.NewOwner__c;
eachCase.NewOwner__c = null;
}
}
}