Skip to content

Instantly share code, notes, and snippets.

@pritaunk
pritaunk / req2.cls
Created October 26, 2017 19:29
Requirement 2 RAD Presentation
//*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
{
@pritaunk
pritaunk / req1
Created October 26, 2017 19:28
Requirement 1 RAD Presentation
//*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) {
@pritaunk
pritaunk / requirement2draft.cls
Last active October 22, 2017 19:12
Requirement 2 final project (draft) line 41 onwards
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;
@pritaunk
pritaunk / datasetup.cls
Created October 22, 2017 17:58
Final Project Apex
//*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;
@pritaunk
pritaunk / requirement1
Created October 22, 2017 17:58
Final Project Apex
//*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);
@pritaunk
pritaunk / Week6hwpriyanka.cls
Created October 14, 2017 13:44
Week6hwpriyanka
//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.
@pritaunk
pritaunk / PriWeek4hw
Created September 25, 2017 21:11
Week4homework
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');
@pritaunk
pritaunk / Week3homeworkPart2
Last active September 19, 2017 21:40
Week3 homework part 2
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]);
}
@pritaunk
pritaunk / PriWeek3HW
Created September 19, 2017 19:26
Priyanka Week3homework
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);
@pritaunk
pritaunk / PriyankaWeek2HW
Created September 15, 2017 21:08
PriyankaWeek2HW
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.
//************************************************************************************************************