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 | |
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
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
//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. |
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 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()); |
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 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')); |
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 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'); |
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 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); |
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 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 |
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 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 |