Skip to content

Instantly share code, notes, and snippets.

<apex:page controller="StatsDemo" docType="html-5.0" lightningStylesheets="true">
<apex:includeScript value="{!$Resource.jStat}"/>
<h1>Calculate</h1>
<apex:form>
<apex:pageBlock>
<apex:pageBlockSection>
<apex:input value="{!probability}" type="number" label="Probability" html-step="any" required="true"/><br></br>
<apex:input value="{!alpha}" type="number" label="Alpha" html-step="any" required="true"/><br></br>
@melissajhansen
melissajhansen / RecipeController.cls
Created April 11, 2021 21:11
The existing RecipeController class with your assigned method signatures added
public inherited sharing class RecipeController {
@AuraEnabled
public static List < Ingredient__c > generateGroceryList(Id recipeId){
//load the ingredients and return them
}
@AuraEnabled
public static void addIngredient(String ingredientName, Integer measurementAmount, String measurementType, ID recipeId){
@melissajhansen
melissajhansen / RecipeTrigger.trigger
Created March 27, 2021 19:04
A simple Recipe trigger
trigger RecipeTrigger on Recipe__c (before insert, after insert, before update, after update, before delete, after delete) {
if (trigger.isBefore && trigger.isInsert) {
RecipeUtil.handleBeforeInsert(trigger.new);
}
if (trigger.isAfter && trigger.isInsert) {
RecipeUtil.handleAfterInsert(trigger.new);
}
if (trigger.isBefore && trigger.isUpdate) {
RecipeUtil.handleBeforeUpdate(trigger.new, trigger.oldMap);
@melissajhansen
melissajhansen / RecipeUtil.cls
Created March 27, 2021 19:02
A simple, static Trigger Handler for the Recipe Trigger
public with sharing class RecipeUtil {
public static void handleBeforeInsert(List < Recipe__c > newRecipes) {
for (Recipe__c rec : newRecipes) {
if (rec.Name==null || rec.Active_Time__c==null || rec.Description__c==null || rec.Active_Time_Units__c==null || rec.Servings__c==null) {
rec.Draft__c = true;
}
}
@melissajhansen
melissajhansen / RecipeHelper.cls
Created March 25, 2020 22:08
Template for starting RecipeHelper
/* A helper class for our Recipe Management App. This class contains static methods
that provide fuctionality related to recipes
*/
public with sharing class RecipeHelper {
// takes ingredient details and creates a corresponding SOBject record with the provided recipe ID as the parent
public static void addIngredient (String ingredientName, Integer measurementAmount, String measurementType, ID recipeId) {
}
@melissajhansen
melissajhansen / RecipeUtil.cls
Created February 4, 2020 03:45
Sample Recipe Util
public with sharing class RecipeUtil {
//Variables to store Trigger.oldMap & Trigger.newMap
List < Recipe__c > newRecipesList;
Map<ID, Recipe__c> newRecipesMap;
Map<ID, Recipe__c> oldRecipesMap;
//Constructor that takes in the map of old recipe records and new/updated recipe records and assigns them to class variables
public RecipeUtil(List < Recipe__c > newRecipes, Map<ID, Recipe__c> newTriggerRecipes, Map<ID, Recipe__c> oldTriggerRecipes) {
@melissajhansen
melissajhansen / RecipeTrigger.trigger
Created February 4, 2020 03:44
Recipe Trigger Example
trigger RecipeTrigger on Recipe__c (before insert, after insert, before update, after update) {
RecipeUtil rUtil = new RecipeUtil(trigger.new, trigger.newMap, trigger.oldMap);
if (Trigger.isBefore) {
if (Trigger.isInsert) {
rUtil.onBeforeInsert();
} else if (Trigger.isUpdate) {
rUtil.onBeforeUpdate();
}
}
@melissajhansen
melissajhansen / Recipe.cls
Created October 6, 2019 21:36
An example of Recipe.cls that references Ingredient
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;
@melissajhansen
melissajhansen / HelperFunctions.cls
Last active October 6, 2019 01:15
A library of generic helper functions
// A library of generic helper functions
global without sharing class HelperFunctions {
global static List<SObject> subsetSobjects (List<SObject> objectList, Integer startIndex, Integer count, Boolean precise) {
//given a list of sObjects a starting index and a count, returns the requested subset.
//If precise is true and the list is not long enough to provide the full requested subset, throws an error. If set to false, returns what is available
//The index must be less than the count
//validate
@melissajhansen
melissajhansen / QueueableObjectUpdater.cls
Created October 6, 2019 01:13
A queueable job that will update any number of SObjects, chaining another job with any objects that could not be updated within limits
//Used to queue the updating of a list of SObjects
//Usage:
//ID jobID = System.enqueueJob(new QueueableObjectUpdater(<SOBJECTSTOUPDATE>));
public class QueueableObjectUpdater implements Queueable {
public List < SObject > objectsToUpdate;
public List < SObject > objectsToQueueForUpdate;