Skip to content

Instantly share code, notes, and snippets.

@sbob-sfdc
sbob-sfdc / inline.js
Created August 30, 2012 10:00
Salesforce Mobile SDK Hybrid App Sample inline.js (001)
//Sample code for Hybrid REST Explorer
function regLinkClickHandlers() {
// avoid jQuery conflicts
var $j = jQuery.noConflict();
// standard logout function
$j('#link_logout').click(function() {
SFHybridApp.logToConsole("link_logout clicked");
SalesforceOAuthPlugin.logout();
@sbob-sfdc
sbob-sfdc / index.html
Created August 30, 2012 10:03
Salesforce Mobile SDK Hybrid App Sample index.html (001)
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<!-- include jquery mobile -->
<link rel="stylesheet" href="jquery/jquery.mobile-1.0b2.min.css" />
<script src="jquery/jquery-1.6.2.min.js"></script>
<script src="jquery/jquery.mobile-1.0b2.min.js"></script>
@sbob-sfdc
sbob-sfdc / InvoiceUtilities.cls
Created September 2, 2012 23:33
Workshop 201, Tutorial 3, Step 2, Apex
public class InvoiceUtilities {
// class method to renumber Line Items for a given Invoice number
// returns a string that indicates success or failure
public static String renumberLineItems(String invoiceName) {
// create a copy of the target Invoice object and it's Line Items
// loop through each Line Item, renumbering as you go
@sbob-sfdc
sbob-sfdc / InvoiceUtilities.cls
Created September 2, 2012 23:34
Workshop 201, Tutorial 3, Step 4.1, Apex
public class InvoiceUtilities {
// class method to renumber Line Items for a given Invoice number
// returns a string that indicates success or failure
public static String renumberLineItems(String invoiceName) {
// create a copy of the target Invoice object and it's Line Items
Invoice__c invoice = [Select i.Name, (Select Name From Line_Items__r ORDER BY Name)
From Invoice__c i
Where i.Name = :invoiceName LIMIT 1];
@sbob-sfdc
sbob-sfdc / InvoiceUtilities.cls
Created September 2, 2012 23:35
Workshop 201, Tutorial 3, Step 4.2, Apex
public class InvoiceUtilities {
// class method to renumber Line Items for a given Invoice number
// returns a string that indicates success or failure
public static String renumberLineItems(String invoiceName) {
// create a copy of the target Invoice object and it's Line Items
Invoice__c invoice = [Select i.Name, (Select Name From Line_Items__r ORDER BY Name)
From Invoice__c i
Where i.Name = :invoiceName LIMIT 1];
@sbob-sfdc
sbob-sfdc / InvoiceUtilities.cls
Created September 2, 2012 23:37
Workshop 201, Tutorial 3, Step 4.3, Apex
public class InvoiceUtilities {
// class method to renumber Line Items for a given Invoice number
// returns a string that indicates success or failure
public static String renumberLineItems(String invoiceName) {
// create a copy of the target Invoice object and it's Line Items
Invoice__c invoice = [Select i.Name, (Select Name From Line_Items__r ORDER BY Name)
From Invoice__c i
Where i.Name = :invoiceName LIMIT 1];
@sbob-sfdc
sbob-sfdc / custombutton.cls
Created September 2, 2012 23:39
Workshop 201, Tutorial 4, Step 1, Apex
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")}
var result = sforce.apex.execute("InvoiceUtilities","renumberLineItems",{invoice:"{!Invoice__c.Name}"});
alert(result);
window.location.reload();
@sbob-sfdc
sbob-sfdc / InvoiceUtilities.cls
Created September 2, 2012 23:40
Workshop 201, Tutorial 4, Step 3, Apex
global with sharing class InvoiceUtilities {
// class method to renumber Line Items for a given Invoice number
// returns a string that indicates success or failure
webservice static String renumberLineItems(String invoiceName) {
// create a copy of the target Invoice object and it's Line Items
Invoice__c invoice = [Select i.Name, (Select Name From Line_Items__r ORDER BY Name)
From Invoice__c i
Where i.Name = :invoiceName LIMIT 1];
@sbob-sfdc
sbob-sfdc / DeleteRestrictInvoice.cls
Created September 2, 2012 23:41
Workshop 201, Tutorial 5, Step 1, Apex
trigger DeleteRestrictInvoice on Invoice__c (before delete) {
// create a list of Invoices in Trigger.oldMap along with their Line Items
List<Invoice__c> invoices = [Select i.Name, (Select Name From Line_Items__r)
From Invoice__c i
Where i.Id IN :Trigger.oldMap.keySet()];
// loop through the Invoices, attaching errors to those that have Line Items
for (Invoice__c invoice : invoices) {
if (!invoice.Line_Items__r.isEmpty()) {
@sbob-sfdc
sbob-sfdc / TestDeleteRestrictInvoice.cls
Created September 2, 2012 23:42
Workshop 201, Tutorial 6, Step 1, Apex
@isTest
private class TestDeleteRestrictInvoice {
// Invoice generator, with or without a Line Item
static Invoice__c createNewInvoice(Boolean withLineItem) {
// Create test Invoice and insert it into the database
Invoice__c invoice = new Invoice__c();
insert invoice;
// Create test Line Item and insert it into the database, if withLineItem == true