This Gist shows code examples for Apex Testing Best Practices. It relys on having the TestFactory in your org.
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
public with sharing class QuoteApprovalController { | |
private SBQQ__Quote__c sbQuote; | |
ApexPages.StandardController qtController; | |
public SBAA__Approval__c[] approvals { | |
get { | |
if (approvals == null) { | |
approvals = SBAA.ApprovalAPI.preview( | |
sbQuote.Id, | |
SBAA__Approval__c.Quote__c | |
); |
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
/*** Apex version of the default logic. | |
* If opportunity's assigned account is assigned to | |
* Case 1: 0 territories in active model | |
* then set territory2Id = null | |
* Case 2: 1 territory in active model | |
* then set territory2Id = account's territory2Id | |
* Case 3: 2 or more territories in active model | |
* then set territory2Id = account's territory2Id that is of highest priority. | |
* But if multiple territories have same highest priority, then set territory2Id = null | |
*/ |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<Package xmlns="http://soap.sforce.com/2006/04/metadata"> | |
<types> | |
<members>Accounts_with_Leads_2</members> | |
<members>Accounts_with_leads</members> | |
<name>ReportType</name> | |
</types> | |
<version>38.0</version> | |
</Package> |
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
<apex:page> | |
<head> | |
<apex:includescript value="//code.jquery.com/jquery-1.11.1.min.js" / > | |
<apex:includescript value="//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js" /> | |
<apex:stylesheet value="//cdn.datatables.net/1.10.4/css/jquery.dataTables.css" /> | |
<!-- I have a static resource called famfamfam which is the zip file from http://www.famfamfam.com/lab/icons/silk/famfamfam_silk_icons_v013.zip --> | |
<style> |
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
public class Loader { | |
public static Map<Id, Account> acountIdToRecordMap { | |
get { | |
if (acountIdToRecordMap == null) { | |
acountIdToRecordMap = new Map<Id, Account> ([Select Name from Account]); | |
} | |
return acountIdToRecordMap; | |
} | |
private set; | |
} |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<Package xmlns="http://soap.sforce.com/2006/04/metadata"> | |
<types> | |
<members>*</members> | |
<name>Profile</name> | |
</types> | |
<types> | |
<members>MyTab</members> | |
<name>CustomTab</name> | |
</types> |
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
public class DynamicEmailController { | |
public DynamicEmailController() {} | |
public String emailRelatedToId {get; set;} | |
public String emailTemplateId {get; set;} | |
public Boolean isHtml {get; set;} | |
private Messaging.SingleEmailMessage renderedEmail { | |
get { |
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
<messaging:emailTemplate subject="{!SUBSTITUTE($Label.AccountEmailSubject,'{0}', relatedTo.Name)}" | |
relatedToType="Account" language="{!relatedTo.Language__c}"> | |
<messaging:htmlEmailBody > | |
{!$Label.EmailBody} | |
</messaging:htmlEmailBody> | |
</messaging:emailTemplate> |
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
// from http://wiki.developerforce.com/page/Apex_Design_Patterns_-_Singleton | |
// What makes this a singleton pattern? Is it that it uses a private constructor? | |
public class AccountFooRecordType { | |
// private static variable referencing the class | |
private static AccountFooRecordType instance = null; | |
public String id {get;private set;} // the id of the record type | |
// The constructor is private and initializes the id of the record type | |
private AccountFooRecordType(){ |
NewerOlder