Skip to content

Instantly share code, notes, and snippets.

View gitmatheus's full-sized avatar

Matheus Gonçalves gitmatheus

View GitHub Profile
@gitmatheus
gitmatheus / MaintenanceRequestHelperTest.cls
Last active March 7, 2018 15:45
MaintenanceRequestHelperTest
@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.
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){
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>();
/*********************************
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';
// 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
SObject[] sObjectAccounts = new SObject[]{ new Account(Name = 'Account Name') };
processAccounts(sObjectAccounts);
private void processAccounts(SObject[] accounts) {
for (Account acct : accounts) System.debug(acct.Name);
}
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);
}
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);
}
public class ParentComponentController {
public String controllerValue;
public void setControllerValue (String s) {
controllerValue = s.toUpperCase();
}
public String getControllerValue() {
return controllerValue;
<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>