Skip to content

Instantly share code, notes, and snippets.

@olgaloza
olgaloza / WeekSeveneHomework.apxc
Created April 9, 2018 20:27
HomeworkSeven();
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
@olgaloza
olgaloza / TestVerifyDate.apxc
Created April 12, 2018 05:40
Homework 8 Trailhead - VerifyDate Unit Test
@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);
@olgaloza
olgaloza / TestRestrictContactByName.apxc
Created April 12, 2018 19:19
Test Apex Triggers Challenge
@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();
@olgaloza
olgaloza / RandomContactFactory.apxc
Created April 12, 2018 19:23
Create Test Data for Apex Tests Challenge
//@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);
}
@olgaloza
olgaloza / StockItemHandler.apxc
Created April 16, 2018 05:13
Final Project - Handler Class
//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
@olgaloza
olgaloza / StockItemHandler_Test.apxc
Last active April 16, 2018 18:12
Final Project - Test Class
@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
@olgaloza
olgaloza / StockItemTrigger.apxt
Created April 16, 2018 05:34
Final Project - Trigger
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);
}
@olgaloza
olgaloza / createStockItems.apxc
Created April 16, 2018 23:18
Final Project - Create sample Stock Items class
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);
@olgaloza
olgaloza / OpportunityUtility.cls
Created October 22, 2018 02:34
RAD 2 Homework 2 - OpportunityUtility class
//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 =
@olgaloza
olgaloza / OpportunityUtility.cls
Created October 22, 2018 02:41
RAD 2 Homework 2 - Opportunity Class
//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 =