This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@isTest | |
private class StockItemHandler_Test { | |
@isTest static void testBeforeInsertFunctionality() { | |
// Implement test to check if item name already exists on an Item. | |
//insert first test item | |
Stock_Item__c firstItem = new Stock_Item__c(); | |
firstitem.Item_Name__c= 'Fish'; | |
insert firstItem; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//The Stock Item Handler's Stock Item records are processed using this utility class. | |
public with sharing class StockItemHandler { | |
//Default Constructor | |
public StockItemHandler() { | |
} | |
//this method will support inserting a new stock item into the database. it will change the name of | |
//the new stock item to 'new item name' + 'duplicate item' before inserted into database. | |
//They should accept lists of Stock_Item__c records from the trigger |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//this trigger will hold an event that calling the before insert and before delete class. | |
//They are in a seperate handler within each specified method | |
trigger StockItemTrigger on Stock_Item__c (before insert, before delete) { | |
StockItemHandler handler = new StockItemHandler(); | |
if(Trigger.isInsert && Trigger.isBefore) { | |
if (Trigger.isInsert) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Original trigger from RAD Dev Console | |
trigger StockItemTrigger on Stock_Item__c (before insert, before delete) { | |
//Instantiate StockItemHandler | |
//Before Insert Handling | |
if(Trigger.isInsert && Trigger.isBefore) { | |
//call the class in your handler for before insert | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OpportunityTriggerHandler { | |
public static void handleBeforeInsert(List<Opportunity> newOpportunities){ | |
//When an Opportunity is inserted, check and see if this account has a rating of 'Hot'. If not, make it 'Hot' | |
//since we consider any account with an open opportunity as hot | |
//Get a map of account records that have opportunities in this trigger | |
//In order to do this, we first need a set of the Account Ids | |
Set<Id> accountIds = new Set<Id>(); | |
for (Opportunity opp : newOpportunities) { | |
accountIds.add(opp.AccountId); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger OpportunityTrigger on Opportunity (before insert) { | |
if (Trigger.isInsert) { | |
if(Trigger.isBefore){ | |
OpportunityTriggerHandler.handleBeforeInsert(Trigger.new); | |
} //else if(Trigger.isAfter){ | |
} // OpportunityTriggerHandler.handleAfterInsert(Trigger.new); | |
//}// | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger ClosedOpportunityTrigger on Opportunity (after insert, after update) { | |
List<Task> taskList = new List<Task>(); | |
for(Opportunity opp : Trigger.new) { | |
//Only create Follow Up Task only once when Opp StageName is to 'Closed Won' on Create | |
if(Trigger.isInsert) { | |
if(Opp.StageName == 'Closed Won') { | |
taskList.add(new Task(Subject = 'Follow Up Test Task', WhatId = opp.Id)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> ThanksGivingFood = new Set<String>(); | |
ThanksGivingFood.add('Turkey'); |
NewerOlder