Skip to content

Instantly share code, notes, and snippets.

View pchittum's full-sized avatar

Peter Chittum pchittum

  • Freelance
  • UK
  • 02:28 (UTC -12:00)
View GitHub Profile
@pchittum
pchittum / ViewStateStudy_controller
Created December 12, 2013 15:39
How Visualforce passes data between two pages. These are examples supporting a post on salesforce.stackexchange.com regarding how to "save" data when redirecting to another page. My argument was that one solution is to take advantage of view state in Visualforce to pass the data around. http://salesforce.stackexchange.com/questions/21899/starts-…
public with sharing class ViewStateStudy_controller {
public String accId{get;set;}
public Account account{get;set;}
public ViewStateStudy_controller()
{
accId = ApexPages.currentPage().getParameters().get('Id');
if(accId != null)
{
@pchittum
pchittum / Merchandise Trigger
Last active December 31, 2015 14:49
INSSET Salesforce Programmer Training
trigger HandleProductPriceChange on Merchandise__c (after update) {
List<Line_Item__c> openLineItems =
[SELECT j.Unit_Price__c, j.Merchandise__r.Price__c
FROM Line_Item__c j
WHERE j.Invoice__r.Status__c = 'Negotiating'
AND j.Merchandise__r.id IN :Trigger.new
FOR UPDATE];
for (Line_Item__c li: openLineItems) {
@pchittum
pchittum / 0 Topic Trigger
Last active August 29, 2015 13:57
Advanced ELEVATE Triggers
In this exercise, you will create a trigger that will address the problem of people creating
bad topics in your org. We will create logic to remove bad topics from chatter posts and replace them
with good topics.
The trigger executes on the TopicAssignment object on insert. It then attempts to delete the bad
TopicAssignment record and insert a new one. Because the trigger is on insert and also calls insert
we risk the problem of a recursive trigger, which must be addressed by using a variable to maintain the
execution state of the trigger.
1. Top prepopulate our "good" topics, run the following execute anonymous code:
@pchittum
pchittum / 0 Salesforce1 Visualforce Study
Last active August 29, 2015 13:57
Simple Visualforce example for focusing on look and feel and publisher action usage from the VF context.
This gist is meant to work through some examples of using Visualforce with Salesforce1. It uses the following features and libraries:
Features
- Visualforce...of course
- Apex remote method
- Canvas publisher JS API
Libs
- onestarter - for S1 look and feel (https://github.com/joshbirk/onestarter)
- jQuery - dependency for onestarter
@pchittum
pchittum / Exec Anonymous 1
Created August 27, 2014 13:13
Strange Delete Behavior
List<Audit_Request__c> ars = Database.query('select id from Audit_Request__c where isDeleted=true ALL ROWS');
System.debug(ars.size());
Database.emptyRecycleBin(ars);
List<Audit_Request__c> ars2 = Database.query('select id from Audit_Request__c where isDeleted=true ALL ROWS');
System.debug(ars2.size());
@pchittum
pchittum / drawing animate
Created August 27, 2014 17:01
OTS Javascript Snippets
// The old smiley function from the previous step
function smiley(x, y) {
moveTo(x, y);
color("yellow");
circle(0, 0, 50);
color("black");
circle(-20, 10, 7);
circle(20, 10, 7);
lineWidth(3);
path("g -20 -10 q 20 -10 0 -50 c");
require 'getoptlong'
data_file = 'data.txt'
words_to_generate = 10
min_length = 3
max_length = 9
opts = GetoptLong.new(
["--datafile", "-d", GetoptLong::OPTIONAL_ARGUMENT],
@pchittum
pchittum / SOSL Test
Created September 25, 2014 10:39
SOSL and Testing for SOSL in Apex
Candidate__c cand = new Candidate__c(first_name__c = 'Sammy', last_name__c = 'Bakersfield', email__c ='s@bakersfield.com');
insert cand;
// the following 3 lines are special; for testing SOSL in testMethods
// see the Apex PDF for more info on SOSL in testMethods
Id [] fixedSearchResults = new Id[] {cand.id};
Test.setFixedSearchResults(fixedSearchResults);
// now we do the controller's sosl search
extension.doSearch();
// verify the results of the search
<apex:page showHeader="false" title="New Order" standardController="Service_Order__c">
<apex:composition template="{!$Site.Template}">
<apex:define name="body">
...
<apex:form styleClass="form" >
<apex:pageMessages id="styledError"/>
<apex:messages id="unstyledError"/>
...
@pchittum
pchittum / package.xml
Created October 11, 2014 15:47
package.xml content to retrieve hackathon stuff for projects in a jam
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>*</members>
<name>ApexClass</name>
</types>
<types>
<members>*</members>
<name>ApexComponent</name>
</types>