This file contains 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 static TestMethod void DataTypes(){ | |
string text1 = 'this text'; | |
string text2 = 'that text'; | |
string text3 = text1 + text2; | |
System.debug(text3); | |
text3 = text3 + 'more text'; | |
System.debug(text3); |
This file contains 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 ContactAfterTrigger on Contact (after insert) { | |
List<Contact> consToUpdate = new List<Contact>(); | |
for(Contact conInTrigger : trigger.new){ | |
Contact c = new Contact();//Create a new instance of an as-yet-unidentified Contact | |
c.Id = conInTrigger.Id;//Set that Contact's ID to an existing ID from the Contacts in Trigger.new | |
c.Department = 'IT';//Change a field value on that Contact | |
consToUpdate.add(c);//Add it to our List so we can update it later when all Contacts in Trigger.new have been prepared | |
} | |
update consToUpdate;//Perform the DML update call outside of our for-loop to avoid Governor Limits (150 DML per transaction)! |
This file contains 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 ContactCompareTrigger on Contact (after update) { | |
//Create an empty Map of Contacts for eventual updates | |
Map<ID, Contact> consToUpdate = new Map<Id, Contact>(); | |
//This is a very common pattern for iterating over the list of records | |
//We use the size() method for Lists to handle each Contact in Trigger.new | |
for(Integer i = 0 ; i < trigger.new.size() ; i++){ | |
Contact old = trigger.old[i]; | |
Contact nw = trigger.new[i];//We cannot use "new" as our variable name, it's a reserved word. |
This file contains 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 (After Update) { | |
Map<ID, Lead> leadsToUpdate = new Map<ID, Lead>();//Create a Map to hold eventual updates | |
//This is a very common pattern for iterating over the list of records | |
//We use the size() method for Lists to handle each Lead in Trigger.new | |
for(Integer i = 0 ; i < trigger.new.size() ; i++){ | |
Lead old = trigger.old[i]; | |
Lead nw = trigger.new[i];//We cannot use "new" as our variable name, it's a reserved word. | |
This file contains 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 DataTypeTestAnswers { | |
public static TestMethod void DataTypes(){ | |
string text1 = 'this text'; | |
string text2 = 'that text'; | |
string text3 = text1 + text2; | |
System.debug(text3); | |
text3 = text3 + 'more text'; |
This file contains 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 Collections { | |
static testMethod void Lists(){ | |
//LISTS ARE AN ORDERED COLLECTION OF DATA | |
//How to instantiate a List with some pre-defined values | |
String someword = 'thread'; | |
List<String> threeStrings = new List<String>{'rope', 'twine', someword}; | |
//Lists have methods that allow us to evaluate or manipulate them |
This file contains 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 (seeAllData = true) | |
public class SOQLqueries { | |
static testMethod void relationshipQueries(){ | |
//Child-to-Parent queries are easy. Simply use the API Name of the lookup field to the parent object | |
//and use dot notation to specify the field on that object you want | |
List<Contact> conAccts = [SELECT FirstName, LastName, Account.Name FROM Contact]; | |
//FIX ME! Use a query with a WHERE filter to only return Contacts from the Account named 'sForce' | |
//List<Contact> sForceconAccts = ??? |
This file contains 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 CollectionsAnswers { | |
static testMethod void Lists(){ | |
//LISTS ARE AN ORDERED COLLECTION OF DATA | |
//How to instantiate an List with some pre-defined values | |
String someword = 'thread'; | |
List<String> threeStrings = new List<String>{'rope', 'twine', someword}; | |
//Lists have methods that allow us to evaluate or manipulate them |
This file contains 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
/* This Apex Class is a Unit Test Class and all the code can be checked by running the test. | |
* Copy this into a new Apex Class named "ControlFlow" and save it. | |
* As you read through it, look for "FIX ME!" and make the changes suggested. | |
* If your changes are correct all the tests (System Asserts) will pass. | |
* | |
* You can also see what's happening in the Logs by opening a Log and checking the Debug Only box | |
* you can compare the line numbers in the Log to the line number in the Class to find a specific | |
* debug entry. | |
*/ |
This file contains 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
/* This Apex Class is a Unit Test Class and all the code can be checked by running the test. | |
* Copy this into a new Apex Class named "ControlFlow" and save it. | |
* As you read through it, look for "FIX ME!" and make the changes suggested. | |
* If your changes are correct all the tests (System Asserts) will pass. | |
* | |
* You can also see what's happening in the Logs by opening a Log and checking the Debug Only box | |
* you can compare the line numbers in the Log to the line number in the Class to find a specific | |
* debug entry. | |
*/ |
OlderNewer