Skip to content

Instantly share code, notes, and snippets.

View metadaddy's full-sized avatar

Pat Patterson metadaddy

View GitHub Profile
@metadaddy
metadaddy / MobileInventory.page
Last active December 21, 2015 04:09
After adding photo capture.
<apex:page standardStylesheets="false" showHeader="false" sidebar="false"
standardController="Merchandise__c" extensions="MobileInventoryExtension"
recordSetVar="products">
<head>
<title>Mobile Inventory</title>
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<apex:stylesheet value="{!URLFOR($Resource.jquerymobile130, 'jquery.mobile-1.3.0.min.css')}" />
@metadaddy
metadaddy / MobileInventory.page
Last active December 21, 2015 04:09
After uploading photo
<apex:page standardStylesheets="false" showHeader="false" sidebar="false"
standardController="Merchandise__c" extensions="MobileInventoryExtension"
recordSetVar="products">
<head>
<title>Mobile Inventory</title>
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<apex:stylesheet value="{!URLFOR($Resource.jquerymobile130, 'jquery.mobile-1.3.0.min.css')}" />
@metadaddy
metadaddy / MobileInventory.page
Last active December 21, 2015 04:09
After making Chatter File public
<apex:page standardStylesheets="false" showHeader="false" sidebar="false"
standardController="Merchandise__c" extensions="MobileInventoryExtension"
recordSetVar="products">
<head>
<title>Mobile Inventory</title>
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<apex:stylesheet value="{!URLFOR($Resource.jquerymobile130, 'jquery.mobile-1.3.0.min.css')}" />
@metadaddy
metadaddy / GoogleInternalRegHandler.cls
Created September 12, 2013 23:24
Simplest possible registration handler for OpenID Connect login from Google.
global class GoogleInternalRegHandler implements Auth.RegistrationHandler{
global User createUser(Id portalId, Auth.UserData data){
User u = [SELECT Id FROM user WHERE GoogleID__c =: data.identifier];
return u;
}
global void updateUser(Id userId, Id portalId, Auth.UserData data){
}
}
@metadaddy
metadaddy / MessageToTask.cls
Last active December 23, 2015 00:49
Visualforce TwiML page and Apex REST method for transcribing a voice message in Twilio and saving is as an Activity to a Lead.
@RestResource(urlMapping='/messagetotask')
global class MessageToTask {
@HttpPost
global static void incomingMessage() {
String expectedSignature =
RestContext.request.headers.get('X-Twilio-Signature');
String url = 'https://' + RestContext.request.headers.get('Host') +
'/services/apexrest' + RestContext.request.requestURI;
Map <String, String> params = RestContext.request.params;
@metadaddy
metadaddy / AnalyticsDemo.page
Last active December 24, 2015 01:29
Calling the Salesforce Winter '14 Analytics API from a Visualforce Page
<apex:page >
<style>
.chartHidden{
display: none;
}
.chartShown{
display: block;
}
</style>
<apex:includeScript value="{!$Resource.jquery}" />
public class PortalHandler implements Auth.RegistrationHandler{
// createUser is called when there is no existing user linked to the incoming
//
public User createUser(Id portalId, Auth.UserData data){
User u;
// Use incoming email for username, since we're working with a portal user
// Look for a existing user with same email address
List<User> l = [SELECT Id, ContactId FROM User WHERE UserName = :data.email];
if (l.size() > 0) {
@metadaddy
metadaddy / MerchandiseChart.page
Last active May 26, 2016 18:59
Visualforce page that uses the Force.com Analytics API to run a report and show a Google Chart based on the report data. We use the Force.com Streaming API to subscribe to a topic and, when the underlying data changes, show a button that allows the user to rerun the report.
<apex:page >
<apex:includeScript value="{!$Resource.cometd}"/>
<apex:includeScript value="{!$Resource.jquery191}" />
<apex:includeScript value="{!$Resource.forcetk}" />
<apex:includeScript value="{!$Resource.jquery_cometd}"/>
<apex:includeScript value="https://www.google.com/jsapi" />
<script>
// Get an instance of the REST API client and set the session ID
var client = new forcetk.Client();
client.setSessionToken('{!$Api.Session_ID}');
@metadaddy
metadaddy / MobileInventory.page
Last active February 20, 2016 18:38
Mobile Inventory page showing HTML5 photo upload - works in Chrome on the desktop, Chatter Mobile 4.2, PhoneGap app etc.
<apex:page standardStylesheets="false" showHeader="false" sidebar="false"
standardController="Merchandise__c" extensions="MobileInventoryExtension"
recordSetVar="products">
<head>
<title>Mobile Inventory</title>
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<apex:stylesheet value="{!URLFOR($Resource.jquerymobile130, 'jquery.mobile-1.3.0.min.css')}" />
@metadaddy
metadaddy / decodeIdToken.js
Created April 4, 2014 18:49
Decode a JSON Web Token (JWT), verifying against a bare RSA key
var jwt = require('jwt-simple');
var getpem = require('rsa-pem-from-mod-exp');
// Decode JWT token, verify with the relevant key from the supplied
// array
function decodeIdToken(idtoken, keys, code) {
var header = JSON.parse(new Buffer(idtoken.split('.')[0], 'base64').toString('utf8'));
for (var i = 0; i < keys.length; i++) {
if (keys[i].kid === header.kid) {