Skip to content

Instantly share code, notes, and snippets.

View martyychang's full-sized avatar

Marty Chang martyychang

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / NullSObjectPropertyBugDemoController.cls
Created November 8, 2014 03:03
It appears that instead of setting a null property to null when returning an sObject via Apex, the property simply isn't set at all and creates odd problems in the UI
public class NullSObjectPropertyBugDemoController {
@AuraEnabled
public static Id editLead(Lead newLead) {
Id newLeadId = null;
try {
upsert newLead;
newLeadId = newLead.Id;
}
@martyychang
martyychang / BatchableExperiment.cls
Last active December 20, 2015 23:10
Apex class that illustrates how a completely self-contained Batchable actually works
/*
* Database.Batchable that can be executed, assuming you have a custom object
* named Experiment__c that already exists in your org, with a custom
* Text field named Title__c
*/
global class BatchableExperiment
implements Database.Batchable<Task>, Iterable<Task>, Iterator<Task> {
/*
* The ID of the Experiment record created for this batch job
@martyychang
martyychang / PieChartRemoteDemo.page
Created November 21, 2014 18:26
How to move JavaScript functions out of the global namespace when used with Visualforce chart components
<apex:page controller="PieChartRemoteController">
<script>
var noData = new Object(); // Simply a dummy placeholder for data attribute
var App = App || {}; // To hold functions
App.retrieveChartData = function(callback) {
var year = document.getElementById('theYear').value;
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.PieChartRemoteController.getRemotePieData}',
year,
@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;
}
}
}
@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"/>