Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / AccountTrigger.apxt
Created April 2, 2018 21:57
WeekSixHomework
//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.
@olgaloza
olgaloza / WeekFiveHomework.apxc
Last active March 26, 2018 23:21
HomeworkFive();
public with sharing class WeekFiveHomework {
public static void soqlPractice() {
//1. Below is a SOQL query that should be returning the top 5 Accounts in our org based on Annual Revenue.
//Something's not quite right, can you fix the query?
List<Account> topFiveAccounts = [SELECT Id, Name, AnnualRevenue FROM Account WHERE AnnualRevenue > 0 ORDER BY AnnualRevenue DESC LIMIT 5];
System.debug('This should be 5: ' + topFiveAccounts.size());
@olgaloza
olgaloza / Bonus
Created March 19, 2018 04:15
HomeworkFour()
//A list of Beth’s favorite shows:
System.debug('Beth\'s favorite shows: ' + favoriteThings.get('beth').get('shows'));
//Is "The Princess Bride" one of Beth’s favorite movies?
System.debug('Is "The Princess Bride" one of Beth’s favorite movies? ' + bethsFavoriteMovies.contains('The Princess Bride'));
@olgaloza
olgaloza / WeekFourHomeork.apxc
Created March 19, 2018 03:19
HomeworkFour()
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> names = new Set<String>();
names.add('Olga');
@olgaloza
olgaloza / WeekThreeHomework.apxc
Created February 27, 2018 03:22
HomeworkThree()
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);
@olgaloza
olgaloza / Get Started with Apex Module Challenge
Created February 27, 2018 00:34
WeekThreeHomework - Trailhead
public class StringArrayTest {
/* WeekThreeHomework from Trailhead module "Get Started with Apex":
* Create an Apex class that returns an array (or list) of strings.
Create an Apex class that returns an array (or list) of formatted strings ('Test 0', 'Test 1', ...). The length of the array is determined by an integer parameter.
The Apex class must be called StringArrayTest and be in the public scope
The Apex class must have a public static method called generateStringArray
The generateStringArray method must return an array (or list) of strings
The number of returned strings is specified by an input parameter of an Integer type
Each string returned must have a value in the format Test n where n is the index of the current string in the array
@olgaloza
olgaloza / WeekTwoHomework Trailhead
Last active October 28, 2024 15:44
Manipulating Records with DML
public class AccountHandler {
/* From "Manipulate Records with DML" Trailhead:
* https://trailhead.salesforce.com/modules/apex_database/units/apex_database_dml
Create a method for inserting accounts.
To pass this challenge, create an Apex class that inserts a new account named after an incoming parameter. If the account is successfully inserted, the method should return the account record. If a DML exception occurs, the method should return null.
The Apex class must be called AccountHandler and be in the public scope
The Apex class must have a public static method called insertNewAccount
The method must accept an incoming string as a parameter, which will be used to create the Account name
Insert the account into the system and then return the record