This file contains 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
//*REQUIREMENT 2*Before a Stock Item is deleted, make sure that the stock on | |
//hand is at 0. If it is not, Create a case so that someone is alerted. | |
//checking if the record is deleted | |
if(trigger.isdelete) { | |
for (stock_item__c stockdelete : trigger.old) //loop through all deleted items | |
{ | |
if (stockdelete.Stock_on_Hand__c < 0) //check if stock on hand is not 0 then create a case to alert | |
{ |
This file contains 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
//*REQUIREMENT 1* Before a Stock Item can be created, check that there is not already | |
// a stock item record with a matching name. | |
//the below creates the new stockitems in a set that | |
//doesn't allow for duplicates. Trigger.new to ensure all new records created | |
//for this object get added to this Set | |
set <string> stockitems = new set <string> (); | |
if (trigger.isInsert) { | |
for (stock_item__c stock : trigger.new) { |
This file contains 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 StockItemTrigger on Stock_Item__c (before insert, after delete) { | |
//*DATA SET UP*created sample records using DML via the execute annonymous window | |
//stock_item__c stock = new stock_item__c (); | |
//stock.Item_Name__c = 'chocolate'; | |
//stock.description__c = 'i love chocolate'; | |
//stock.minimum_stock_level__c = 10; | |
//stock.stock_on_hand__c = 10; | |
//stock.list_price__c = 50; |
This file contains 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
//*DATA SET UP*created sample records using DML via the execute annonymous window | |
//stock_item__c stock = new stock_item__c (); | |
//stock.Item_Name__c = 'chocolate'; | |
//stock.description__c = 'i love chocolate'; | |
//stock.minimum_stock_level__c = 10; | |
//stock.stock_on_hand__c = 10; | |
//stock.list_price__c = 50; | |
//insert stock; | |
This file contains 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
//*REQUIREMENT 1* Before a Stock Item can be created, check that there is not already | |
// a stock item record with a matching name. | |
//the below creates the new stockitems in a set that | |
//doesn't allow for duplicates. Trigger.new to ensure all new records created | |
//for this object get added to this Set | |
set <string> stockitems = new set <string> (); | |
for (stock_item__c stock : trigger.new) { | |
stockitems.add(stock.Item_Name__c); |
This file contains 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 first line of our trigger gives the Trigger's name (AccountTrigger), names the object (Account) and lists the trigger_events that will cause the code below to execute | |
//For example, "before insert" indicates that before an account record (or records) is inserted, the trigger will be called. | |
//For more information on trigger syntax: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_syntax.htm | |
trigger AccountTrigger on Account (before insert, before update, before delete, after insert, after update, after delete, after undelete) { | |
//Each section of code below handles a different event & timing combination. For now, we are demonstrating a trigger that has all of the logic right here. | |
//Later on we'll be looking at other ways of handling Trigger events using handler classes, but for now, we want to keep all the logic in once place as | |
//we're learning. |
This file contains 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 WeekFourHomework { | |
public static void setsReview(){ | |
//Your assignment: Play with Sets! | |
// 1. Create a set of Strings and add at least 5 entries | |
Set <string> SetofAccounts = new set <string> (); | |
SetofAccounts.add ('Canon'); |
This file contains 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 StringArrayTest { | |
//The Apex class must be called 'StringArrayTest' and be in the public scope. (done) | |
//The Apex class must have a public static method called 'generateStringArray'. (done) | |
//The 'generateStringArray' method must return an array (or list) of strings. (done) | |
public static list <string> generateStringArray (integer n){ | |
list<string> thislist = new list<string>(); | |
for (integer i=0 ; i<10;i++) { | |
thislist.add('Test ' + i); | |
system.debug(thislist[i]); | |
} |
This file contains 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 WeekThreeHomework { | |
//Let's practice calling different methods by writing our very own methods. You will write and save methods in the space below | |
//that call the existing methods you see already written here. Ready? Let's Go! | |
//Sample: Here is a public method that calls the getfavoriteColorsMethod below and prints the results to our debug log | |
public static void printOutFavoriteColorsDemo () { | |
List < String > favoriteColors = getFavoriteColors(); | |
system.debug('Here are the favorite colors: '+ favoriteColors); |
This file contains 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 WeekTwoHomework { | |
public static void homeworkAssignmentMethod () { | |
//Read through the set-up below and then complete the code following the prompts. When you're done, make sure to compile (save) your work | |
//Open Execute Anonymous in the Developer Console and execute your code by typing in: WeekTwoHomework.homeworkAssignmentMethod(); | |
//Read through the debug statements to make sure you're done your work correctly. | |
//************************************************************************************************************ |
NewerOlder