Skip to content

Instantly share code, notes, and snippets.

View katelessardrad's full-sized avatar

KateLessardRAD katelessardrad

View GitHub Profile
//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 u
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 LIMIT 5];
System.debug('This should be 5: ' + topFiveAccounts.size());
public with sharing class WeekFiveHomework {
public static void setsReview(){
//Your assignment: Play with Sets!
// 1. Create a set of Strings and add at least 5 entries
Set <String> pizzaToppings = new Set <String>();
pizzaToppings.add ('sauce');
pizzaToppings.add('cheese');
//1. Write a public method that calls the getCitiesForExpansion method to get a list of cities, then add
//another city to the list before printing it to the debug log.
//(see the sample above for an example of calling that method-You can even start by copying and pasting that method here, renaming and modifying it)
public static void printOutCitiesForExpansionDemo(){
List<String> cities = getCitiesForExpansion();
cities.add('Paris');
System.debug('Here are the cities: ' + cities);
}
public with sharing class WeekThreeHomework {
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: WeekThreeHomework.homeworkAssignmentMethod();
//Read through the debug statements to make sure you're done your work correctly.
//************************************************************************************************************
@katelessardrad
katelessardrad / gist:153d0875bd1c114a0fe5bdbd8e8a0405
Last active August 26, 2019 19:12
Wk 2 HW: Commenting on Code
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() {
//Declare the Integer minimumCartValue and assign value equal to 50
Integer minimumCartValue = 50;
public with sharing class WeekTwoHomework {
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'
/*Make Nespresso Coffee for Kate
Prepare Materials and Utensils
Select Nespresso Pod
Get Mug (preferably a Salesforce one)
Get Spoon
Get Milk Frother
Get Milk
Prepare Machine
Turn lever all the way Right to open and eject old pod
Place Nespresso pod in cartridge holder
public with sharing class Welcome {
//Welcome! I'm a comment and I'm here to tell you what this particular class file is for. The developer who created this class added
//me so that future developers, like yourself, would have a quick little introduction to what this class does.
//The two little slashes tell the compiler* that everything following on this line is a note
//for humans and not code that needs to be executed
// (* A compiler is the computer program that translates this code into executable computer instructions)
//But you know what? This set of comments is already several lines long and getting longer. I'm tired of typing two slashes every time