Skip to content

Instantly share code, notes, and snippets.

@sfdcgin
sfdcgin / InvokingTestDataFactory
Created April 21, 2020 02:03
Rad2 Test DataFactory
@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
@sfdcgin
sfdcgin / DailyLeadProcessor
Created March 29, 2020 00:58
W7 Rad2 Schedulable Apex
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) {
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
@sfdcgin
sfdcgin / Calculator Testing
Created March 23, 2020 23:33
W6 Homework
@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(){
@sfdcgin
sfdcgin / gist:f7f679e77a98dfba37c254a634f832a0
Created March 16, 2020 20:40
W4 RecipeHandler__ Test
@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();
@sfdcgin
sfdcgin / W4 RecipeHandler
Last active March 16, 2020 20:34
W4 RecipeHandler
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
@sfdcgin
sfdcgin / W4 RecipeTrigger
Last active March 16, 2020 20:36
W4 RecipeTrigger
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();
}
@sfdcgin
sfdcgin / LeadHandler
Created March 3, 2020 04:27
RadII Homework Week 3 Lead Trigger Handler
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;
@sfdcgin
sfdcgin / LeadTrigger
Created March 3, 2020 04:24
RadII Homework Week 3 Lead Trigger Handler
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
// *********************************************************************************
@sfdcgin
sfdcgin / ContactAndLeadSearch
Last active February 25, 2020 05:55
RadII Week2 HW
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;
}
}