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 |
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 TestVerifyDate { | |
//testing that if date2 is within 30 days of date1, should return date 2 | |
@isTest static void testDate2within30daysofDate1() { | |
Date date1 = date.newInstance(2018, 03, 20); | |
Date date2 = date.newInstance(2018, 04, 11); | |
Date resultDate = VerifyDate.CheckDates(date1,date2); | |
Date testDate = Date.newInstance(2018, 04, 11); | |
System.assertEquals(testDate,resultDate); |
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 TestRestrictContactByName { | |
@isTest static void testInvalidName() { | |
//try inserting a Contact with INVALIDNAME | |
Contact myConact = new Contact(LastName='INVALIDNAME'); | |
insert myConact; | |
// Perform test | |
Test.startTest(); |
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 | |
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); | |
} |
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
//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 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() { | |
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 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 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 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 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 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
//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 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
//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 = |