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 CaseTriggerHandler { | |
//Handler Methods | |
public static void onBeforeInsert(List<Case> newCases) { | |
//Set default Reason if not provided at case creation | |
for ( Case c : newCases) { | |
if (c.Reason == NULL) { | |
System.debug('---->Case reason is '+c.Reason); | |
c.Reason = 'Other'; | |
} | |
else { |
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 CaseTrigger on Case (before insert, before update, before delete, after insert, after update, after delete, after undelete) { | |
if(Trigger.isInsert && Trigger.isBefore){ | |
CaseTriggerHandler.onBeforeInsert(Trigger.new); | |
} | |
if(Trigger.isInsert && Trigger.isAfter){ | |
CaseTriggerHandler.onAfterInsert(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
//utility class for homework 2 | |
public with sharing class OpportunityUtility { | |
//this is static a method that Takes an integer as an argument and returns a list of the top n Opportunities, | |
//ordered first by amount in descending order, then by Account Name. | |
//n is the integer that was passed in as an argument | |
//Include: Opportunity ID, Amount, Account Name, MainCompetitors__c, CloseDate, Stage | |
public static List<Opportunity> getTopOpportunities(Integer n) { | |
List<Opportunity> topOpportunities = |
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
//utility class for homework 2 | |
public with sharing class OpportunityUtility { | |
//this is static a method that Takes an integer as an argument and returns a list of the top n Opportunities, | |
//ordered first by amount in descending order, then by Account Name. | |
//n is the integer that was passed in as an argument | |
//Include: Opportunity ID, Amount, Account Name, MainCompetitors__c, CloseDate, Stage | |
public static List<Opportunity> getTopOpportunities(Integer n) { | |
List<Opportunity> topOpportunities = |
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
//utility class for homework 2 | |
public with sharing class OpportunityUtility { | |
//this is static a method that Takes an integer as an argument and returns a list of the top n Opportunities, | |
//ordered first by amount in descending order, then by Account Name. | |
//n is the integer that was passed in as an argument | |
//Include: Opportunity ID, Amount, Account Name, MainCompetitors__c, CloseDate, Stage | |
public static List<Opportunity> getTopOpportunities(Integer n) { | |
List<Opportunity> topOpportunities = |
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 createStockItems { | |
public static void createSampleStockItems(Integer numberOfItems) { | |
//Putting new stock items into a list to bulkify the code | |
List<Stock_Item__c> stockItemsList = new List<Stock_Item__c>(); | |
//Loop through and add stock items: | |
for (Integer i = 0; i < numberOfItems; i++) { | |
System.debug('i = ' + i); | |
Stock_Item__c si = new Stock_Item__c(); | |
si.Item_Name__c = 'Sample Stock Item ' + (i+1); |
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, before delete) { | |
//Instantiate StockItemHandler | |
//Before Insert Handling | |
if(Trigger.isInsert && Trigger.isBefore) { | |
//call the class in your handler for before insert | |
StockItemHandler.onBeforeInsert(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
@isTest | |
private class StockItemHandler_Test { | |
@isTest static void testBeforeInsertFunctionality() { | |
try { | |
// Implement test code | |
// to test, try creating 2 items with same names. | |
Stock_Item__c item1 = new Stock_Item__c(Item_Name__c = 'Test Stock Item'); | |
Stock_Item__c item2 = new Stock_Item__c(Item_Name__c = 'Test Stock Item'); | |
/* FOR SOME REASON I COULDN'T GET THIS TEST VERSION TO WORK |
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
//A Utility class to process Stock Item records from the Stock Item Handler | |
public with sharing class StockItemHandler { | |
//Default Constructor | |
public StockItemHandler() { | |
} | |
//Create methods here to handle the before insert, before delete and utility processes described in the requirements | |
//They should accept lists of Stock_Item__c records from the trigger |
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
//@isTest | |
public class RandomContactFactory { | |
public static List<Contact> generateRandomContacts(Integer numContactsToGenerate, String FName) { | |
List<Contact> contactList = new List<Contact>(); | |
for(Integer i=0;i<numContactsToGenerate;i++) { | |
Contact c = new Contact(FirstName=FName + ' ' + i, LastName = 'Contact '+i); | |
contactList.add(c); | |
System.debug(c); | |
} |
NewerOlder