Skip to content

Instantly share code, notes, and snippets.

@melissajhansen
melissajhansen / LDSErrorTest.cmp
Last active January 16, 2018 16:54
LDS Error Example
<aura:component implements="forceCommunity:availableForAllPageTypes,force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId" access="public">
<aura:attribute name="contactRecord" type="Contact"/>
<aura:attribute name="recordError" type="String"/>
<aura:attribute name="returnedError" type="String"/>
<force:recordData aura:id="recordLoader"
recordId="{!v.recordId}"
({
changeNameToSusie: function(cmp, event, helper) {
console.log("LDSErrorTest.handleRecordUpdated: entered");
var contact = cmp.get("v.contactRecord");
console.dir(contact);
contact.FirstName = "Susie";
cmp.set("v.contactRecord", contact);
@melissajhansen
melissajhansen / Part2SOQLExercises.cls
Last active October 19, 2018 22:55
Part 2 SOQL & SOSL Practice
public with sharing class Part2SOQLExercises {
public static void funWithAggregates () {
//1)
//Let's create a query to count how many opportunities we have that are over $100,000 dollars
//Since we're just getting a count, we can put the result directly intp an integer variable
Integer bigOppsCount = [SELECT COUNT() FROM Opportunity WHERE Amount > 100000];
System.debug('We have ' + bigOppsCount + ' Opportunities over 100K');
public with sharing class ContactTriggerHandlerV2 {
//Variables to store Trigger.oldMap & Trigger.newMap
Map<ID, Contact> oldContactsMap;
Map<ID, Contact> newContactsMap;
//Constructor that takes in the map of old contact records and new/updated contact records and assigns them to class variables
public ContactTriggerHandlerV2(Map<ID, Contact> oldTriggerContacts, Map<ID, Contact> newTriggerContacts) {
oldContactsMap = oldTriggerContacts;
newContactsMap = newTriggerContacts;
public with sharing class ContactTriggerHandlerV3 {
//Has the Contact trigger already executed?
public static boolean hasExecuted = false;
//Variables to store Trigger.oldMap & Trigger.newMap
Map<ID, Contact> oldContactsMap;
Map<ID, Contact> newContactsMap;
trigger ContactTriggerV3 on Contact (before insert, before update, before delete, after insert, after update, after delete, after undelete) {
/***************This Trigger should only be run ONCE******************/
if( ContactTriggerHandlerV3.hasExecuted ){
return; // prevent recursive re-entry
}
ContactTriggerHandlerV3.hasExecuted= true;
/*********************************************************************/
@melissajhansen
melissajhansen / StockItem.cls
Last active October 28, 2018 18:07
Object Oriented Class that represents our Stock_Item__c Object and provides abstracted functionality
//Object Oriented Class that represents our Stock_Item__c Object and provides abstracted functionality
public with sharing class StockItem {
//class variables defined here
public String sObjectID;
public Decimal listPrice; // ex 3.4 signifies $3.40
public String name;
public String description;
public Integer minimumStockNeeded;
public with sharing class SampleBadMethods {
public class SampleCustomException extends Exception{}
//This method throws a custom exception, because we have a specific data requirement (positive integers)
//Without the custom check and exception, this code would run, but not meet our specs
public static Integer iAddUpPositiveIntegers (Integer intA, Integer intB) {
//First validate that we have positive integers only
@isTest
private class HandleBadMethodsTest {
@isTest
static void testCustomException() {
//validate that our method will reject negative integers
Boolean exceptionWasThrown = false;
try {
@melissajhansen
melissajhansen / SampleFromTrailhead.HTML
Created November 24, 2018 19:35
Sample Visualforce Page with Standard Controller
<apex:page standardController="Account">
<apex:form>
<apex:pageBlock title="My Content" mode="edit">
<apex:pageBlockButtons>
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="My Content Section" columns="2">
<apex:inputField value="{!account.name}"/>
<apex:inputField value="{!account.site}"/>
<apex:inputField value="{!account.type}"/>