Skip to content

Instantly share code, notes, and snippets.

//Used to queue the updating of a list of SObjects
//Usage:
//ID jobID = System.enqueueJob(new AsynchObjectsUpdate(<SOBJECTSTOUPDATE>));
public class AsynchObjectsUpdate implements Queueable {
List < SObject > objectsToUpdate;
//list constructor
@melissajhansen
melissajhansen / Job_ScheduledNutritionUpdate.cls
Created October 6, 2019 00:20
Simple demonstration of a Scheduled Job
global without sharing class Job_ScheduledNutritionUpdate implements Schedulable {
// Usage for nightly run at 12:05 AM
//Job_ScheduledNutritionUpdate snu = new Job_ScheduledNutritionUpdate();
//string sch = '0 05 0 * 1-12 ? *';
//system.schedule('Job_ScheduledNutritionUpdate',sch, snu);
global void execute(SchedulableContext sc) {
System.debug('Ok, the Job_ScheduledNutritionUpdate is running!!!!');
@melissajhansen
melissajhansen / Ingredient.cls
Last active October 16, 2019 21:45
Extended Ingredient sample class to have an @future method calling out for mock nutrition information
// Author: Niki Vankerk
// Date: 10/2019
public with sharing class Ingredient {
//class variables defined here
public Double measurement;
public String measurementType;
public String description;
public String name;
@isTest
private class Recipe_Test {
/* Validate that a bad id throws an exception on instantiation */
@isTest static void badIdTest() {
try {
Recipe myRecipeWithBadId = new Recipe('ThisIsNotAGoodId');
} catch (Exception e) {
System.debug('exception : '+e);
@isTest
private class Recipe_Test {
/* Validate that a bad id throws an exception on instantiation */
@isTest static void badIdTest() {
try {
Recipe myRecipeWithBadId = new Recipe('ThisIsNotAGoodId');
} catch (Exception e) {
System.debug('exception : '+e);
@TestSetup
static void dataCreation(){
Account a = TestFactory.getAccount('Muddy Waters Inc.', true);
Contact c = TestFactory.getContact(a.id, 'Muddy', 'Waters', true);
Opportunity opp = New Opportunity();
opp.name = 'Long lost record';
opp.accountId = a.id;
opp.closeDate = Date.today().addDays(14);
opp.stageName = 'prospecting';
insert opp;
@TestSetup
static void dataCreation(){
Account a = TestFactory.getAccount('Muddy Waters Inc.', true);
Contact c = TestFactory.getContact(a.id, 'Muddy', 'Waters', true);
Opportunity opp = New Opportunity();
opp.name = 'Long lost record';
opp.accountId = a.id;
opp.closeDate = Date.today().addDays(14);
opp.stageName = 'prospecting';
insert opp;
@isTest
public class TestFactory {
public static Account getAccount(String name, Boolean doInsert){
Account a = new Account(name = name);
if(doInsert){
insert a;
}
return a;
}
public static Contact getContact(Id accountId, String fname, String lname, Boolean doInsert){
@isTest
private class Recipe_Test {
// create a test Recipe obect in memory, then call the create() method and validate that a corresponding SObject was created
@isTest static void createRecipeSObjectTest() {
// Data Setup
Recipe newRecipe = new Recipe(30, 'Minutes', 'Test Recipe', 4);
// Add a description, now a required field (TODO - the constructor should take description!)
newRecipe.description = 'A test recipe';
@melissajhansen
melissajhansen / Recipe.cls
Last active September 22, 2019 22:23
A Sample Encapsulation Class with logic and functionality for Recipes in our Recipe App
public with sharing class Recipe {
//class variables defined here
public Decimal activeMinutes;
public Double activeTime;
public String activeTimeUnits;
public String description;
public String name;
public String season;