Skip to content

Instantly share code, notes, and snippets.

@forcethesales
forcethesales / dynamic APEX
Created September 27, 2020 15:32
dynamic apex to check CRUD and FLS
//FROM https://eltoro.secure.force.com/DynamicApexToCheckCrudAndFls
public class demoDynamicApexMethods {
public void SObject_Information() {
Schema.DescribeSObjectResult drSObj = Schema.sObjectType.Account;
System.debug(drSObj.getChildRelationships());
System.debug(drSObj.getRecordTypeInfos());
System.debug(drSObj.getRecordTypeInfosByID());
System.debug(drSObj.getRecordTypeInfosByName());
System.debug(drSObj.isCreateable());
System.debug(drSObj.isAccessible());
@forcethesales
forcethesales / Recipe Helper
Last active December 21, 2020 17:21
RAD II Final Project
public class RecipeHelper {
public static void addIngredient (String ingredientName, Integer measurementAmount, String measurementType, ID recipeId) {
//code
//Your code should create an Ingredient SObject in memory and insert it in the database.
//The ingredient should have the recipe id provided as its parent.
Ingredient__c ingred = new Ingredient__c();
ingred.Name = ingredientName;
ingred.Calories__c = 44;
ingred.Measurement__c=measurementAmount;
@forcethesales
forcethesales / RecipeHelper
Last active April 6, 2020 01:01
RAD II Final Project Option 1
public class RecipeHelper {
public static void addIngredient (String ingredientName, Integer measurementAmount, String measurementType, ID recipeId) {
//code
//Your code should create an Ingredient SObject in memory and insert it in the database.
//The ingredient should have the recipe id provided as its parent.
Ingredient__c ingred = new Ingredient__c();
ingred.Name = ingredientName;
ingred.Calories__c = 44;
ingred.Measurement__c=measurementAmount;
@forcethesales
forcethesales / Test example that i really like
Last active April 14, 2021 15:47
Test Example that I really like
//source https://trailhead.salesforce.com/content/learn/modules/asynchronous_apex/async_apex_scheduled
@isTest
private class RemindOppyOwnersTest {
// Dummy CRON expression: midnight on March 15.
// Because this is a test, job executes
// immediately after Test.stopTest().
public static String CRON_EXP = '0 0 0 15 3 ? 2022';
static testmethod void testScheduledJob() {
// Create some out of date Opportunity records
@isTest
public class AccountProcessorTest {
@TestSetup
static void dataCreation(){
//create accounts
List<Account> newAccts = new List <Account>();
Account account1 = new Account(Name = 'Adam');
newAccts.add(account1);
@isTest
private class RecipeTriggerHandler_Test {
@TestSetup
static void dataCreation(){
// create difficult recipe
Recipe__c rec = new Recipe__c();
rec.Name = 'Test Recipe 3';
rec.Active_Time__c = 2;
rec.Description__c = 'recipe';
@isTest
private class myDataGenerationTests {
@TestSetup
static void loadTestDataFromStaticResource(){
List<sObject> accounts = Test.loadData(Account.SObjectType, 'Mock_Data');
}
@isTest static void testLoadAccountsFromStaticResource() {
List<Account> accts = [SELECT ID FROM Account];
system.assert(accts.size() == 15, 'expected 16 accounts');
}
@forcethesales
forcethesales / Trigger
Last active March 17, 2020 15:21
Prasanna's week 4 homework
//Trigger by Prasanna Cherlopalle
//comments and questions by Jessie Rymph start with JR. Other comments are from Prasanna.trigger RecipeTrigger2 on Recipe__c ( before insert, after insert, before update, after update, before delete, after delete) {
if (Trigger.isBefore) {
if (Trigger.isInsert) {
// Instantiate the Handler and set Trigger records
// JR: so this is making an instance of the handler specifically for this time it runs.
// JR: see SFDC99 Example https://www.sfdc99.com/2015/01/19/the-one-trigger-per-object-design-pattern/
// JR: This is sending a list with Trigger.new
RecipeTriggerHandler2 handler = new RecipeTriggerHandler2(Trigger.new);
//calling the method from the handler
public class RecipeTriggerHandler {
//trigger variables
//JR: Are these variables empty until the constructors actually populate them with the maps/lists?
List<Recipe__c> newRecipes;
Public static void updateRecipes(List<recipe__c> listRecipes) {
//loop through the recipes that were just created or updated
For (Recipe__c recipe:listRecipes){
@forcethesales
forcethesales / homework week 3
Created March 5, 2020 02:34
successful trigger and handler for after insert
//Lead Trigger
trigger LeadTrigger on Lead (after insert, after update) {
if (Trigger.isInsert) {
LeadCreateTaskTriggerHandler.createTaskAfterInsert(Trigger.new);
}
}
//Lead Trigger Handler