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 WeekOneHomework { | |
public static void introToPrimitives() { | |
//Primitives are the simplest elements in a programming language | |
/* A selection of primitives in Apex: | |
Integer: A number that does not have a decimal point, like 1 or 789 or -34 | |
Decimal: A number that includes a decimal point like 1.34 or 456.78907654 | |
String: Any set of characters surrounded by single quotes, like 'Apple' or 'I Love Strings' or '2 Legit 2 Quit' |
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 CommentingOnCodeExercise { | |
//Your Assignment is to add comments describing what is being done in the methods below. | |
//Call out the concepts you learned in your readings and in class. | |
public static void cartValues() { | |
Integer minimumCartValue = 50;//We are declaring a new variable type integer and assigning a value 50 to it | |
Integer itemA = 10;//We are declaring a new variable type integer and assigning a value 10 to it |
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 WeekTwoHomework { | |
public static void homeworkAssignmentMethod() { | |
//Read through the set-up below and then complete the code following the prompts. When you're done, make sure to compile (save) your work | |
//Open Execute Anonymous in the Developer Console and execute your code by typing in: WeekTwoHomework.homeworkAssignmentMethod(); | |
//Read through the debug statements to make sure you're done your work correctly. | |
//************************************************************************************************************ |
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 |
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 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 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
//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 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
//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. |
OlderNewer