Skip to content

Instantly share code, notes, and snippets.

//NewProj2 isn't a meaningful Apex name. NewProjectTrigger?
trigger NewProj2 on Opportunity (before update) {
for (Opportunity o : Trigger.new)
{
if(o.StageName == 'Closed Won')
{
try
{
SFL5_Projects__c[] proj = [Select Name From SFL5_Projects__c
@joshbirk
joshbirk / 1. OpportunitiesController.cls
Last active August 29, 2015 14:05
OppHomeComponent
public class OpportunitiesController {
public List<Opportunity> opportunities {get; set;}
public OpportunitiesController() {
opportunities = [SELECT Id, Name, Account.Name, ExpectedRevenue, CloseDate from Opportunity WHERE OwnerId = :UserInfo.getUserId()];
}
}
@joshbirk
joshbirk / FlickrHandler.cls
Created August 18, 2014 21:32
FlickrView AKA KittenForce (aka puppyforce)
public with sharing class FlickrHandler {
public class FlickrList {
public string title {get; set;}
public string link {get; set;}
public List<FlickrData> items {get; set;}
}
public class FlickrData {
public string title {get; set;}
@joshbirk
joshbirk / BlogLog_Services.cls
Created April 29, 2014 18:51
Blog Log CSV Example
global class BlogLog_Services implements Messaging.InboundEmailHandler {
public BlogLog_Services() {}
public Document document {
get {
if (document == null)
document = new Document();
return document;
}
@joshbirk
joshbirk / 1: Create a new REST Endpoint
Created April 7, 2014 19:03
ELEVATE Extra Credit: Custom REST Responses
/*
In the Programmers workbook there is a tutorial on creating a basic REST endpoint using Apex. A common scenario with these
endpoints is needing to enhance the message that gets sent down to client. You can do this easily within Apex by defining
a custom class to use as a response, which will be converted to JSON by the platform.
To complete this extra credit:
1. Create a class from the code below
2. Update the POST and DELETE endpoints to use the RESTMessage class
3. Test the new endpoint with unit test in the next class
*/
@joshbirk
joshbirk / 1: Use the Email Interface
Created April 7, 2014 18:45
ELEVATE Extra Credit: Apex Email Services
/* Various features of the Salesforce1 platform require Apex to utilize specific interfaces so the a level of
functionality can be assumed. One of these is the inbound email interface. This allows Apex to be used as an
email service which can process incoming emails.
To complete this extra credit:
1. Create an Apex class that uses the Inbound Email interface using the code below
2. Complete the acceptEmail function so that it returns an email with more information on the product
3. Add the Apex class as an email service and test it manually.
*/
@joshbirk
joshbirk / 1: Create Streaming Topics
Created April 7, 2014 18:12
ELEVATE Extra Credit: jQuery and the Streaming API
/*
The Streaming API allows clients to get updates on data changes in near real-time.
This is done by keeping an open connection instead repeatedly polling the server, which is much more lightweight.
To accomplish this connection, you need a cometD capable client. Luckily, there is a jQuery plugin for this -
which makes jQuery in Visualforce an easy way to test out the API.
To complete this extra credit:
1. Create a Streaming Topic with the following code.
2. Include jQuery, the cometD and iCanHas libraries in a Visualforce page.
3. Add the necessary JavaScript to connect to the Streaming API
@joshbirk
joshbirk / 1: WarehousePull.cls
Last active August 29, 2015 13:58
HTTP Mock Extra Credit
/*
This is an Apex class which calls out to an endpoint to find new merchandise items to be inserted into the system.
Before it can be deployed to production, however, it needs a unit test. Since it makes an HTTP callout, however,
the unit test will require a mock class.
Before you can test the class, you will also need to open a Remote Site to let your Salesforce instance know
it is a legitimate site:
1. Go to Setup | System Administration | Security Controls | Remote Site Settings.
2. Click New.
@joshbirk
joshbirk / TestPage.page
Created March 28, 2014 20:47
Quick OneStarter Example
<apex:page standardController="Invoice__c" extensions="LineItemRemotingExtension" showHeader="false">
<apex:stylesheet value="{!URLFOR($Resource.OneStarter,'icons.css')}"/>
<apex:stylesheet value="{!URLFOR($Resource.OneStarter,'styles.css')}"/>
<apex:stylesheet value="{!URLFOR($Resource.OneStarter,'OneStarter.css')}"/>
<apex:includeScript value="//code.jquery.com/jquery-1.10.2.min.js" />
<apex:includeScript value="{!URLFOR($Resource.TouchSwipe,'jquery.touchSwipe.min.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.OneStarter,'jquery.onestarter.js')}"/>
<apex:includeScript value="/canvas/sdk/js/publisher.js"/>
@joshbirk
joshbirk / ListDetailController.cls
Last active August 29, 2015 13:57
PageBlock Components Test
public with sharing class ListDetailController {
public List<Account> accounts {get; set;}
public Account account_detail {get; set;}
public Id account_id {get; set;}
public Boolean showBack {get; set;}
// The extension constructor initializes the private member
// variable mysObject by using the getRecord method from the standard
// controller.