This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@isTest | |
public class MyRecipeTesting { | |
//Invoking the TestDataFactory | |
static testmethod void testIngredients() { | |
//METHOD 1 -class receive a list of ingredients back based on #specified via parm | |
List<Recipe__c> lstRecipes = New List<Recipe__c>(); | |
// ORIGINAL CALL -->List<Ingredient__c> lstIngredients = TestDataFactory.createIngredients(5); | |
List<Ingredient__c> lstIngredients = TestDataFactory.createIngredients(5,lstRecipes); | |
// Run some tests this will vary on circumstances |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Global class DailyLeadProcessor implements Schedulable { | |
global void execute(SchedulableContext ctx) { | |
//*TH Playground 5 | |
List<Lead> lstLead = [SELECT Id, LeadSource FROM Lead WHERE LeadSource = '' Limit 200]; | |
List<Lead> lstUpdts = new List<Lead>(); | |
For (Lead l:lstLead){ | |
l.LeadSource = 'Dreamforce'; | |
lstUpdts.add(l); | |
} | |
if(!lstUpdts.isEmpty() || lstUpdts.size() > 0) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AccountProcessor { | |
@future | |
public static void countContacts(set<ID> setAcctIDs) { | |
//Function: Iterate through the accounts received to retrieve # of related contacts; update where applicable | |
// ?design-- what if delete or inactivate a contact probably may want to update then back to 0 How would like to handle. Perhaps restrict to 'active' contacts in query. | |
// ?? added size on contact cuz in future method and thought perhaps other DML statements may impact query results & try to prevent additional updates. | |
// ? is that overkill ?? | |
// NOTES: | |
// can use these to test in ExecAnonymous swap out parm name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@isTest | |
public class Calculator_Tests { | |
//Question: did not use start & stop test as no i-o for this class and no need to reset gov.limits | |
// is that reasonable? | |
@isTest | |
static void testPosAddition(){ | |
System.assertEquals(4, Calculator.addition(2, 2),'test positive addition'); | |
} | |
@isTest | |
static void testPosSubtraction(){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@isTest | |
//******************************************** | |
// Couple questions in method posGenTask() | |
//******************************************** | |
// Positive Tests for general methods in Recipe Handler | |
//test class is generally private -- no use other than for testing | |
private class RecipeHandler_Test { | |
@istest static void posCkDraft(){ | |
Recipe__c recipe = new Recipe__c(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class RecipeHandler { | |
//Handler class variables to make available for methods within the Handler | |
//Remember if an Insert / before statement, there is no need for DML statment, good for defaulting values & validations | |
List<Recipe__c> lstNewRecipes; | |
Map<ID, Recipe__c> oldMapRecipes; | |
// use old map & new list --> newMap not needed Map<ID, Recipe__c> newMapRecipes; | |
//Constructor that takes in the list of Recipes for before operations |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger RecipeTrigger on Recipe__c (before insert, After Insert, Before Update, After Update) { | |
//Instantiate Recipe Handler which divides the trigger logic into smaller chunks of code for maintainability & readability. | |
RecipeHandler recipeHandler = new RecipeHandler(Trigger.new, trigger.oldMap); | |
If (Trigger.isBefore) { | |
if (trigger.isInsert){ | |
recipeHandler.handleRecipeBeforeInsert(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LeadHandler{ | |
//Handler class variables to make available for methods within the Handler | |
List<Lead> lstLeads; | |
Map<ID, Lead> oldMapLead; | |
//Constructor that takes in the list of Leads & a map of old Lead records and assigns them to class variables to be used | |
Public LeadHandler(List<Lead> lstLeads, Map<ID, Lead> oldMapLead) { | |
this.lstLeads = lstLeads; | |
this.oldMapLead = oldMapLead; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger LeadTrigger on Lead (after insert, after update) { | |
//************************************************************************************ | |
// LeadTrigger Function: | |
// 1. For new leads, generate a Task for follow up witin 7 Days | |
// 2. For existing leads, where there product interest has changed, generate | |
// a Task for follow up within 3 days. | |
// Date: 3/2/20 | |
// Version: 1.0 Initial | |
// ********************************************************************************* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ContactAndLeadSearch { | |
public static List<List<sObject>> searchContactsAndLeads(string parmName){ | |
//Trailhead Exercise PG5 SOSL Query searching NAME Fields for value specified via the parameter | |
List<List<sObject>> searchList = [FIND :parmName IN NAME FIELDS | |
RETURNING Contact(Name),Lead(FirstName)]; | |
System.debug(searchList); | |
return searchList; | |
} | |
} |
NewerOlder