Skip to content

Instantly share code, notes, and snippets.

View jsullivanlive's full-sized avatar

James Sullivan jsullivanlive

View GitHub Profile
@jsullivanlive
jsullivanlive / EmailLogic.cls
Created February 8, 2016 22:47
Salesforce Email Merge
public class EmailLogic {
public static String renderTemplate(sObject sobj, String template) {
for (String fieldName : fields(sobj.getSObjectType())) {
String key = '{!' + fieldName + '}';
while (template.containsIgnoreCase(key)) {
try {
Integer foundPosition = template.indexOfIgnoreCase(key, 0);
template = template.left(foundPosition) +
String.valueOf(sobj.get(fieldName)) +
@jsullivanlive
jsullivanlive / anon.apex
Created October 12, 2015 18:37
Update date field based on lead history using anonymous apex
Lead[] leads = [
select Id,
(select Id, Field, OldValue, NewValue, CreatedDate from Histories order by CreatedDate asc)
from Lead
where Status='Closed'
and Closed_Date__c = null
order by LastModifiedDate asc
limit 1000
];
Lead[] toUpdate = new Lead[]{};
@jsullivanlive
jsullivanlive / gist:88668ea7c98aa11b7e04
Last active August 29, 2015 14:23
Update user story ranks from raw data using data in a json field
Map<String, Id> rank = new Map<String, Id>();
Map<Id, User_Story__c> stories = new Map<Id, User_Story__c>([
select Id, Customer_Story_ID__c, Customer_Story_Raw_Data__c
from User_Story__c
where Project__r.Name = 'projectname'
]);
for (User_Story__c us : stories.values()) {
if (String.isBlank(us.Customer_Story_Raw_Data__c)) continue;
Map<String, Object> data = (Map<String, Object>)JSON.deserializeUntyped(us.Customer_Story_Raw_Data__c);
// rally DragAndDropRank is not unique, so combine with id
<apex:page showHeader="false" sidebar="false" expires="0" cache="false" docType="html" controller="TargetX_Base.TX_CommunitiesBase" extensions="AppStartController">
<apex:composition template="{!defaultTemplate}">
<!-- use head for extra css or important js before dom load -->
<apex:define name="head"/>
<!-- set subheading tag to disable the boilerplate heading -->
<apex:define name="subheader"/>
<apex:define name="content">
/*
* Author: Kevin O'Hara
* Date: 02/10/2012
*
* Description: The Async class aims to circumvent a limitation of asynchronous (@future)
* methods in Salesforce. The current @future implementation will only allow for primitives
* or collections of primitives to be passed into an @future method. The Async class uses
* native JSON serialization/deserialization to allow for passing an SObject, or List<SObject>
* into an asynchronous method for DML operations. A helper method is also included for making
* the serialization processes simpler.
@jsullivanlive
jsullivanlive / 1. result
Last active December 14, 2015 21:49
Was going to deploy a rest web service on Heroku and was curious if there was a big difference between handling very simple requests between the standard ways of deploying to Heroku for Flask/wsgi/Go: Golang Requests per second: 6446.75 [#/sec] (mean) Flask Requests per second: 1029.64 [#/sec] (mean) gunicorn+wsgi Requests per second: 2164.54 [#…
Golang Requests per second: 6446.75 [#/sec] (mean)
Flask Requests per second: 1029.64 [#/sec] (mean)
gunicorn+wsgi Requests per second: 2164.54 [#/sec] (mean)