Skip to content

Instantly share code, notes, and snippets.

@niavesper
niavesper / gist:6f63c68a586f6cc8b97ed02a7111789e
Created February 14, 2020 02:45
Week_1_Homework_Primitives.cls
public static void primitivesExercise() {
//You do this part!
//1. Declare three primitives variables, an Integer, a String and a Decimal
Integer numCatPaws;
String catName;
Decimal numFurnitureDestroyed;
//2. Assign values to your three new variables
numCatPaws = 4;
//Making a cup of tea
//walk over to the electric kettle
//lift the electric kettle off its base
//open the lid of the kettle
//walk over to the sink
//turn on the water faucet
//fill the kettle above the MIN mark
//turn off the water faucet
//close the lid of the kettle
//a class called "CommentingOnCodeExercise" is being declared
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.
*/
//A method called "cartValues" is being declared that can be used outside of this class (hence "public")
public static void cartValues() {
public with sharing class WeekTwoHomework {
public static void conditionalsExercise() {
Boolean result;
// 1. Write a comparison statement that evauates to false and assign the result to our result variable
//Don't forget to maintain indentation!
result = 6 > 8;
@niavesper
niavesper / gist:4ea24c597f2c106f2ddf4a048d339d6a
Created February 29, 2020 21:46
Week3_Homework_Loops.cls
public with sharing class WeekThreeHomework {
public static void homeworkAssignmentMethod() {
//Read through the setup 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: WeekThreeHomework.homeworkAssignmentMethod();
//Read through the debug statements to make sure you're done your work correctly.
//************************************************************************************************************
@niavesper
niavesper / gist:16b901ac1503dcff5807b45f8c99d67f
Created February 29, 2020 21:46
Week3_Homework_Loops.cls
public with sharing class WeekThreeHomework {
public static void homeworkAssignmentMethod() {
//Read through the setup 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: WeekThreeHomework.homeworkAssignmentMethod();
//Read through the debug statements to make sure you're done your work correctly.
//************************************************************************************************************
public with sharing class WeekFourHomework {
//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 getCitiesForExpansion below and prints the results to our debug log
public void printOutCitiesForExpansionDemo() {
//The code on the left of the equals sign instantiates a list of Strings, the code on the right side calls our method and returns a list of cities
//the equals sign assigns the returned value, to the list we created
public with sharing class WeekFiveHomework {
// Remember Sets & Maps?? We did a little practice with Lists in week 2, but we need to make sure we know how to use Sets & Maps as well!!
public static void setsReview(){
//Your assignment: Play with Sets!
// 1. Create a set of Strings and add at least 5 entries
@niavesper
niavesper / gist:e874cbe8cf887c137a8316aa60026cbe
Created March 23, 2020 01:27
Week6_Homework_SOQL_And_Loops
public with sharing class WeekSixHomework {
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());
//We're calling this 'BadAccountTrigger' because this trigger has business logic directly coded in the trigger file. It's also using
//way more parameters (on line 7) than it actually uses in the trigger itself. Both of these are considered bad practice.
//Business logic coded directly in a trigger and having extra stuff in your code both make the code hard to read and hard to maintain.
//The 'GoodAccountTrigger' shows how to use a handler class with your trigger and is much simpler to read.
//For more information on trigger syntax: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_syntax.htm
trigger AccountTriggerBad 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