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 | |
private class MaintenanceRequestHelperTest { | |
//Leverage a @testSetup method to reduce execution time and increase maintainability | |
@testSetup | |
static void allTheDataForThisTestClass() { | |
// Principle #1: Create records from scratch! | |
// Remember that Records created in a test setup method are rolled back at the end of test class execution. |
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 MaintenanceRequest on Case (after update) { | |
// This is an after update trigger, but you can use the same structure for other trigger events. | |
// Remember: One trigger per object. | |
//Create a Map to store the Maintenance Requests to evaluate: | |
Map<Id, Case> casesToEvaluate = new Map<Id, Case>(); | |
if(Trigger.isAfter && Trigger.isUpdate){ | |
for(Case maintenance : Trigger.new){ |
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 MaintenanceRequestHelper { | |
public static void updateWorkOrders(Map<Id, Case> cases){ | |
// When testing this method, consider using a Test Data Factory | |
// class or create all the data | |
// Create a list of Cases | |
List<Case> maintenance_routineList = new List<Case>(); | |
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
/********************************* | |
Imagine three strings: | |
- one with a single space | |
- one null | |
- one not empty and not null | |
*********************************/ | |
String singleSpaceString = ' '; | |
String nullString = null; | |
String notEmptyString = 'Samwise Gamgee is the real hero'; |
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
// First, let's declare a list of Strings, | |
// using the previous String variables: | |
String[] stringsToConcat = | |
new String[]{singleSpaceString, nullString, notEmptyString}; | |
// Now we can use a join method to concatenate the variables: | |
String joinedText = String.join(stringsToConcat, ''); | |
// This is the result: | |
|DEBUG|concatenated joinedText: Samwise Gamgee is the real hero |
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
SObject[] sObjectAccounts = new SObject[]{ new Account(Name = 'Account Name') }; | |
processAccounts(sObjectAccounts); | |
private void processAccounts(SObject[] accounts) { | |
for (Account acct : accounts) System.debug(acct.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
SObject[] sObjectCustomObject = new SObject[]{ new Custom_Object__c(Name = 'Custom Object Name') }; | |
processCustomObject(sObjectCustomObject); | |
private void processCustomObject(SObject[] customObjects) { | |
for (Custom_Object__c obj : customObjects) System.debug(obj.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
SObject[] sObjectAccounts = new SObject[]{ new Account(Name = 'Account Name') }; | |
processCustomObject(sObjectAccounts); | |
// Using a list of sObject Accounts as a parameter (that expects a list of Custom Objects). | |
private void processCustomObject(Custom_Object__c[] customObjects) { | |
//for (Custom_Object__c customObj : customObjects) System.debug(customObj.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
public class ParentComponentController { | |
public String controllerValue; | |
public void setControllerValue (String s) { | |
controllerValue = s.toUpperCase(); | |
} | |
public String getControllerValue() { | |
return controllerValue; |
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
<apex:component controller="ParentComponentController"> | |
<apex:attribute name="componentValue" description="Attribute on the component." | |
type="String" required="required" assignTo="{!controllerValue}"/> | |
<apex:pageBlock title="My Parent Custom Component"> | |
<p> | |
<code>componentValue</code> is "{!componentValue}" | |
<br/> | |
<code>controllerValue</code> is "{!controllerValue}" | |
</p> | |
</apex:pageBlock> |
OlderNewer