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 RecipeHelper { | |
| //define custom exception | |
| public class RecipeException extends Exception {} | |
| // takes ingredient details and creates a corresponding SOBject record with the provided recipe ID as the parent | |
| public static void addIngredient (String ingredientName, Integer measurementAmount, string measurementType, Id recipeId) { | |
| Ingredient__c newIngredient = new Ingredient__c(); | |
| newIngredient.Name = ingredientName; | |
| newIngredient.Measurement__c = measurementAmount; |
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 RecipeHelper { | |
| //takes ingredient details and creates a corresponding SOBject record with the provided recipe ID as the parent | |
| public static void addIngredient (String ingredientName, Integer measurementAmount, string measurementType, Id recipeId) { | |
| Ingredient__c newIngredient = new Ingredient__c(); | |
| newIngredient.Name = ingredientName; | |
| newIngredient.Measurement__c = measurementAmount; | |
| newIngredient.Measurement_Type__c = measurementType; | |
| newIngredient.Recipe__c = recipeId; |
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 { | |
| @isTest | |
| public static void additionPositiveTest() { | |
| integer a = 2; | |
| integer b = 3; | |
| integer c = Calculator.addition(a, b); | |
| System.assertEquals(5, c, 'expected result is 5'); | |
| } |
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 RecipertriggerHandler_Test { | |
| @isTest | |
| static void testIsDraft() { | |
| Recipe__c recipe = new Recipe__c(); | |
| recipe.Name = 'New Recipe'; | |
| insert recipe; |
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) { | |
| if (Trigger.isBefore) { | |
| if (Trigger.isInsert) { | |
| ReciperTriggerHandler.beforeInsert(Trigger.new); | |
| } | |
| if (Trigger.isUpdate) { | |
| ReciperTriggerHandler.beforeUpdate(Trigger.newMap); |
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 (before insert, before update, after insert, after update) { | |
| if (Trigger.isAfter) { | |
| if(Trigger.isInsert) { | |
| LeadTriggerHandler.LeadAfterInsert(Trigger.new); | |
| } | |
| else if(Trigger.isUpdate) { | |
| LeadTriggerHandler.LeadAfterUpdate(Trigger.newMap, Trigger.oldMap); | |
| } | |
| } |
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
| /Create a class that has a method accepting two strings. The method searches for contacts | |
| that have a last name matching the first string and a mailing postal code matching the second. | |
| It gets the ID and Name of those contacts and returns them. | |
| public class ContactSearch { | |
| public static List<Contact> searchForContacts(string lastName, string mailingCode) { | |
| List<Contact> myContacts = [SELECT Name, Id FROM Contact WHERE LastName =: lastName AND MailingPostalCode =: mailingCode]; | |
| System.debug(myContacts); | |
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
| /*Create an Apex class with a method that returns an array (or list) of formatted strings ('Test 0', 'Test 1', ...). | |
| The length of the array is determined by an integer parameter.*/ | |
| public class StringArrayTest { | |
| public static List<String> generateStringArray(Integer returnedStrings) { | |
| List<String> names = new List<String>(); | |
| for (integer i = 0; i < returnedStrings; i++) { | |
| string oneName = 'Test ' + i; | |
| names.add(oneName); |
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
| //The first line of our trigger gives the Trigger's name (AccountTrigger), names the object (Account) and lists the trigger_events that will cause the code below to execute | |
| //For example, "before insert" indicates that before an account record (or records) is inserted, the trigger will be called. | |
| //For more information on trigger syntax: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_syntax.htm | |
| trigger AccountTrigger on Account (before insert, before update, before delete, after insert, after update, after delete, after undelete) { | |
| //Each section of code below handles a different event & timing combination. For now, we are demonstrating a trigger that has all of the logic right here. | |
| //Later on we'll be looking at other ways of handling Trigger events using handler classes, but for now, we want to keep all the logic in once place as | |
| //we're learning. |
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 AccountAddressTrigger on Account (before insert, before update) { | |
| for (Account a : Trigger.new) { | |
| if (a.Match_Billing_Address__c = true && a.BillingPostalCode != null) { | |
| a.ShippingPostalCode = a.BillingPostalCode; | |
| } | |
| } | |
| } |
NewerOlder