Skip to content

Instantly share code, notes, and snippets.

View sarabirchtree's full-sized avatar

sarabirchtree

View GitHub Profile
trigger StockItemTrigger on Stock_Item__c (before insert, before delete) {
//Before Insert Handling
if(Trigger.isInsert && Trigger.isBefore) {
//call the class in your handler for before insert
StockItemTriggerHandler.handleBeforeInsert(Trigger.new);
}
//Before Delete Handling
if(Trigger.isDelete && Trigger.isBefore) {
@istest
private class LowStockItems_Test {
@istest
static void testGettingLowStockItems() {
//Create Stock Item with low stock (Stock on Hand < Min Stock)
Stock_Item__c item1 = new Stock_Item__c();
@sarabirchtree
sarabirchtree / StockItemTriggerHandler_Test.cls
Created May 28, 2025 04:02
StockItemTriggerHandler_Test
@istest
private class StockItemTriggerHandler_Test {
@istest
static void duplicateStockItemNameTest() {
//Test the handleBeforeInsert method that should update Item Name if it is a duplicate
//Insert a new Stock Item
public class LowStockItems {
//Public class that returns a list of Stock Items with low stock
public static List<Stock_Item__c> getLowStockItems() {
//Create List of Stock Items where Item Stock is Low = TRUE
List<Stock_Item__c> lowStockItems =
[SELECT Id, Item_Name__c, Item_Stock_is_Low__c, Minimum_Stock_Level__c, Stock_on_Hand__c FROM Stock_Item__c WHERE Item_Stock_is_Low__c = TRUE];
System.debug('# of Low Stock Items: '+ lowStockItems.size());
@sarabirchtree
sarabirchtree / StockItemTriggerHandler.cls
Created May 28, 2025 04:01
StockItemTriggerHandler
public class StockItemTriggerHandler {
public static void handleBeforeInsert(List<Stock_Item__c> newStockItems){
//Get existing Stock Items
List<Stock_Item__c> existingStockItems = [SELECT Id, Item_Name__c FROM Stock_Item__c];
//Create list of existing sotck item names
List<String> existingStockItemNames = new List<String>();
//Add existing stock item names to list
public with sharing class AccountTriggerHandler {
public static void handleBeforeInsert(List<Account> newAccounts){
for (Account a : newAccounts) {
if (a.Est_Annual_Sales__c >= 5000000) {
a.Priority__c = 'Highest';
} else if (a.Est_Annual_Sales__c >= 3000000) {
a.Priority__c = 'High';
} else if (a.Est_Annual_Sales__c >= 1000000) {
a.Priority__c = 'Standard';
public with sharing class WeekSevenHomework {
//Assignment: The following method is supposed to create the number of accounts specified in the argument that it takes.
//Each Account should be named 'Sample Account #sampleNumber' where sample number is the count. So if you created 2 Accounts
//one would be called 'Sample Account 1' and the other 'Sample Account 2'
//Also, when we're done inserting them, we will create a case for each one with a Status of 'New', Origin of 'New Account' and the
//desription and subject of your choice.
//This isn't working quite right. Can you use your debugging skills to fix it? I had to comment it out since it won't compile
public with sharing class WeekSixHomework {
// Remember Sets & Maps?? We did a little practice with Lists in week 2, but we need to make sure we know how to use Sets & Maps as well!!
public static void setsReview(){
//Your assignment: Play with Sets!
// 1. Create a set of Strings and add at least 5 entries
Set<String> portlandParks = new Set<String>();
@sarabirchtree
sarabirchtree / weekFiveHomework.cls
Created April 26, 2025 03:03
WeekFiveHomework
public with sharing class WeekFiveHomework {
//Let's practice calling different methods by writing our very own methods. You will write and save methods in the space below
//Note: There are existing pre-written methods at the bottom of this class that you can use to help with your own methods. Ready? Let's go!
//Sample: Here is a public method that calls the getCitiesForExpansion below and prints the results to our debug log
public static void printOutCitiesForExpansionDemo() {
//The code on the left of the equals sign instantiates a list of Strings, the code on the right side calls our method and returns a list of cities
//the equals sign assigns the returned value, to the list we created
@sarabirchtree
sarabirchtree / WeekFourHomework.cls
Created April 16, 2025 20:28
WeekFourHomework
public with sharing class WeekFourHomework {
public static void soqlPractice() {
//1. Below is a SOQL query that should be returning the top 5 Accounts in our org based on Annual Revenue.
//Something's not quite right, can you fix the query?
List<Account> topFiveAccounts = [SELECT Id, Name, AnnualRevenue FROM Account WHERE AnnualRevenue != 0 ORDER BY AnnualRevenue DESC LIMIT 5];
System.debug('This should be 5: ' + topFiveAccounts.size());