Skip to content

Instantly share code, notes, and snippets.

@olgaloza
olgaloza / WeekOneHomework.apxc
Last active February 19, 2018 22:37
RADWomen(); homework_1_a
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'
@olgaloza
olgaloza / CommentingOnCodeExercise.apxc
Last active February 19, 2018 22:37
RADWomen(); homework_1_b
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
@olgaloza
olgaloza / WeekTwoHomework.apxc
Created February 26, 2018 21:45
homeworkTwo()
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.
//************************************************************************************************************
@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
@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 / 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 / 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 / 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 / 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 / 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.