Skip to content

Instantly share code, notes, and snippets.

@niavesper
niavesper / RecipeHandler2
Last active April 14, 2021 18:14
RecipeHandler2.cls: First method throws an error when one of the key fields is blank, which is the requirement of Week 6 homework. RecipeHandler2_Test contains testing for exception throwing: positive (lines 25-93) and negative (lines 178-223). RecipeTrigger2.trigger calls on the exception-throwing method
public with sharing class RecipeHandler2 {
// Week 6 homework: Exception Testing
public static void throwException(List<Recipe__c> exceptionRecipes){
for (Recipe__c r : exceptionRecipes){
if (r.Name == null || r.Active_Time__c == null || r.Description__c == null || r.Active_Time_Units__c == null || r.Servings__c == null){
r.addError('One of the key ingredients is null!');
}
}
}
@niavesper
niavesper / RecipeHandler.cls
Last active April 14, 2021 18:10
RecipeHandler.cls: First method checks Draft checkbox when one of the key fields is blank, which is the requirement of Week 5 homework. This is not new, it just gives context to the negative tests. RecipeHandler__Test.cls: same as week 5 homework, plus some negative tests. Negative tests start at line 151. RecipeTrigger.trigger: same as Week 5 h…
public with sharing class RecipeHandler {
public static void checkDraft(List<Recipe__c> draftRecipes) {
for (Recipe__c r : draftRecipes){
if (r.Name == null || r.Active_Time__c == null || r.Description__c == null || r.Active_Time_Units__c == null || r.Servings__c == null){
r.Draft__c = true;
}
}
}
@isTest
private class RecipeHandler_Test {
@testSetup
static void dataCreation(){
// Create data for testing Draft recipes
List <Recipe__c> draftRecipes = new List<Recipe__c>();
for(integer i=0; i < 4; i++){
Recipe__c r = new Recipe__c(
Name = 'Draft Recipe ' + i,
@niavesper
niavesper / cls
Created March 30, 2021 00:32
Recipe Trigger and Handler
public with sharing class RecipeHandler {
public static void checkDraft(List<Recipe__c> draftRecipes) {
for (Recipe__c r : draftRecipes){
if (r.Name == null || r.Active_Time__c == null || r.Description__c == null || r.Active_Time_Units__c == null || r.Servings__c == null){
r.Draft__c = true;
}
}
}
<messaging:emailTemplate recipientType="User"
relatedToType="Case"
subject=" A New Case for the Communications Team Has Been Created: {!relatedTo.CaseNumber}"
replyTo="dhasupport@utah.gov" >
<messaging:htmlEmailBody >
<p>A new case for the Communications team has been created via the self-service web form (Hazel).</p>
<br/>Contact Name: {!relatedTo.Contact.Full_Name__c}
<br/>Subject: {!relatedTo.Subject}
<apex:component controller="getCaseSysChanges" access="global">
<apex:attribute name="currentCaseId" type="Id" description="Id of the case" assignTo="{!caseId}"/>
<table border = "2" cellspacing = "5">
<tr>
<td><b>Sys Change Number</b></td>
<td><b>Type</b></td>
<td><b>Due Date</b></td>
<td><b>Description</b></td>
</tr>
<apex:repeat value="{!sysChanges}" var="sc">
public class getCaseSysChanges {
public Id caseId {get;set;}
public List<System_Change__c> getSysChanges()
{
List<System_Change__c> sysChanges;
sysChanges = [SELECT Name, Type_of_Change__c, Target_Completion_Date__c, Description_of_Change__c FROM System_Change__c WHERE
RecordType.DeveloperName ='MarCom_Secondary_Sys_Change'
AND Case__r.Id =: caseId];
return sysChanges;
}
@niavesper
niavesper / LeadTrigger.tgr
Created March 21, 2021 20:56
LeadTrigger
trigger LeadTrigger on Lead (after insert, after update) {
switch on Trigger.operationType {
when AFTER_INSERT{
LeadHandler.handleAfterInsert(trigger.new);
}
when AFTER_UPDATE{
LeadHandler.handleAfterUpdate(trigger.new, trigger.oldMap);
}
}
@niavesper
niavesper / LeadHandler.cls
Created March 21, 2021 20:53
LeadHandler
public with sharing class LeadHandler {
public static void handleAfterInsert(List<Lead> newLeads){
List<Task> newTasks = new List<Task>();
for (Lead l : newLeads){
Task t = new Task();
t.WhoId = l.Id;
switch on l.ProductInterest__c{
when 'Cookbook Authorship'{
t.Subject = 'Follow up About Cookbook Authorship';
public class WeekTwoHomework {
// method (a)
public static void showAccNames(){
integer i=0;
for (Contact c : [SELECT Id, Account.Name, Account.Industry FROM Contact]){
i++;
System.debug ('Name of Account # ' + i + ' is ' + c.Account.Name);
}
}