Skip to content

Instantly share code, notes, and snippets.

@mwelburn
mwelburn / gist:e9292113c1e638bfe45e
Created May 6, 2014 03:41
AggregateResult - Wellness Activities
global with sharing class WellnessTrackerController {
@RemoteAction
global static List<WellnessRank> getWeeklyRanking() {
List<WellnessRank> rankList = new List<WellnessRank>();
/*
* Not sure why, but needed to alias the relationship fields
* http://salesforce.stackexchange.com/questions/19381/reference-fields-on-parent-object-in-aggregate-query
*/
@mwelburn
mwelburn / gist:3ac0eb70c1ebd2f51257
Created May 5, 2014 22:28
Remote Object - Create Record
var activity = new RemoteObjectModel.Wellness_Activity__c();
activity.set('Wellness_Goal__c', goal.Id);
activity.set('User__c', userId);
activity.create(function(error, result, event) {
if (error != null) {
alert(error);
} else {
alert('Activity logged successfully!');
}
});
@mwelburn
mwelburn / 1 - Define Remote Objects
Last active August 29, 2015 14:01
Sample code to run a basic query using Salesforce remote objects
<apex:remoteObjects jsNamespace="RemoteObjectModel">
<apex:remoteObjectModel name="Wellness_Goal__c" fields="Id,Name,Points__c,Active__c"/>
<apex:remoteObjectModel name="Wellness_Activity__c" fields="Id,Wellness_Goal__c,User__c"/>
</apex:remoteObjects>
@mwelburn
mwelburn / DescribeResult.cls
Created February 21, 2014 02:50
Successful way to cache the Schema token
public class Criteria
{
public String objectType {get;set;}
public String fieldName {get;set;}
@TestVisible private transient Schema.DescribeFieldResult describeResult
@TestVisible private String Schema.sObjectField schemaField;
/* Other methods that leverage the fields describe to determine things like whether its a picklist,
what picklist values are available, etc... */
@mwelburn
mwelburn / DescribeResult.cls
Last active August 29, 2015 13:56
Example of failed attempts to serialize a describe result
public class Criteria
{
public String objectType {get;set;}
public String fieldName {get;set;}
// The following will fail when the page tries to serialize it into the view state unless it is set as transient
@TestVisible private String Schema.DescribeFieldResult describeResult;
/* Other methods that leverage the fields describe to determine things like whether its a picklist,
what picklist values are available, etc... */
<apex:page standardController="Contact" tabStyle="Contact" extensions="ContactWithAccountAttachmentsController">
<apex:detail inlineEdit="true"/>
<apex:pageBlock title="Account Attachments">
<apex:pageBlockTable value="{!noteAttachments}" var="n" rendered="{!noteAttachments.size > 0}">
<apex:column headerValue="Type" value="{!n.Type}"/>
<apex:column headerValue="Title">
<apex:outputLink value="/{!n.Id}" title="{!n.Name}" target="_self">{!n.Name}</apex:outputLink>
</apex:column>
<apex:column headerValue="Last Modified" value="{!n.LastModifiedDateString}"/>
<apex:column headerValue="Created By" value="{!n.OwnerName}"/>
<apex:page controller="testLookup">
<apex:form >
<apex:pageBlock id="incomeBlock" mode="edit">
<apex:pageBlockSection columns="1">
<apex:pageBlockTable value="{!opptys}" var="t">
<apex:facet name="footer">
</apex:facet>
<apex:column headerValue="Id">
<apex:outputField value="{!t.Id}"/>
</apex:column>
public class testLookup
{
public List<Opportunity> opptys {get;set;}
public testLookup()
{
opptys = new List<Opportunity>();
opptys.add(new Opportunity());
}
}