\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{tienhung} \pdfinfo{ /Title (apex-basic.pdf) /Creator (Cheatography) /Author (tienhung) /Subject (Apex basic Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{1AAEED} \definecolor{LightBackground}{HTML}{F0F9FD} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Apex basic Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{tienhung} via \textcolor{DarkBackground}{\uline{cheatography.com/198331/cs/41948/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}tienhung \\ \uline{cheatography.com/tienhung} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 15th January, 2024.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{4} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Apex}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{What is Apex \newline % Row Count 1 (+ 1) Apex is a strongly typed, object-oriented Programming language that allows developers to execute the flow and transaction control statements on the force.com platform server in conjunction with calls to the Froce.com API.% Row Count 6 (+ 5) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Understanding the Apex Syntax}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Variable Decalation} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Loop Statement} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Flow Control Statement} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{List Datatype} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Map Datatype} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Set Datatype} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{DML Statement} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{SOQL Query} \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Apex Trigger} \tn % Row Count 9 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.58361 cm} x{2.84939 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Data types}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Boolean} & Boolean isTrue = true; \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{String} & String greeting = 'Hello, Salesforce!'; \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{Integer} & Integer quantity = 10; \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} Long & Long bigNumber = 1234567890; \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} \seqsplit{Decimal} & Decimal price = 99.99; \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} \seqsplit{Double} & Double largeValue = 1234567890.123456789; \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} Date & Date today = Date.today(); \tn % Row Count 12 (+ 1) % Row 7 \SetRowColor{white} Time & Time currentTime = Time.now(); \tn % Row Count 13 (+ 1) % Row 8 \SetRowColor{LightBackground} \seqsplit{Datetime} & Datetime currentDatetime = Datetime.now(); \tn % Row Count 15 (+ 2) % Row 9 \SetRowColor{white} ID & Id recordId = '001R00000123456789'; \tn % Row Count 17 (+ 2) % Row 10 \SetRowColor{LightBackground} Blob & Blob type is more complex and typically used for binary data like images. \tn % Row Count 20 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{List Datatype}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{Method List Datatype} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} add(listElement) or add(index, listElement) & Adds the specified element to the end of the list. \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} \seqsplit{contains(listElement)} & Returns true if the list contains the specified element. \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} equals(list2) & Compares the current list to another list, returning true if they are equal. \tn % Row Count 11 (+ 4) % Row 4 \SetRowColor{LightBackground} isEmpty() & Returns true if the list is empty. \tn % Row Count 13 (+ 2) % Row 5 \SetRowColor{white} remove(index) & Removes the element at the specified position in the list. \tn % Row Count 16 (+ 3) % Row 6 \SetRowColor{LightBackground} size() & Returns the number of elements in the list. \tn % Row Count 19 (+ 3) % Row 7 \SetRowColor{white} sort() & Sorts the elements of the list in ascending order. \tn % Row Count 22 (+ 3) % Row 8 \SetRowColor{LightBackground} \seqsplit{deepClone(preserveId}, \seqsplit{preserveReadonlyTimestamps}, preserveAutonumber) & Creates a deep clone of the list. You can specify whether to preserve record IDs, readonly timestamps, and autonumber fields. \tn % Row Count 29 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.13289 cm} x{2.30011 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Set Datatypes}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{add(setElement)} & Adds an element to the set if it is not already present. \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} clear() & Removes all of the elements from the set. \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} clone() & Makes a duplicate copy of the set. \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{contains(setElement)} & Returns true if the set contains the specified element. \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} equals(set2) & Compares this set with the specified set and returns true if both sets are equal; otherwise, returns false. \tn % Row Count 15 (+ 5) % Row 5 \SetRowColor{white} isEmpty() & Returns true if the set has zero elements. \tn % Row Count 17 (+ 2) % Row 6 \SetRowColor{LightBackground} \seqsplit{remove(setElement)} & Removes the specified element from the set if it is present. \tn % Row Count 20 (+ 3) % Row 7 \SetRowColor{white} size() & Returns the number of elements in the set (its cardinality). \tn % Row Count 23 (+ 3) % Row 8 \SetRowColor{LightBackground} toString() & Returns the string representation of the set. \tn % Row Count 25 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{0.99557 cm} x{2.43743 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Map Datatype}} \tn % Row 0 \SetRowColor{LightBackground} clear() & Removes all of the key-value mappings from the map. \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} clone() & Makes a duplicate copy of the map. \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{containsKey(key)} & Returns true if the map contains a mapping for the specified key. \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} \seqsplit{deepClone()} & Makes a duplicate copy of a map, including sObject records if this is a map with sObject record values. \tn % Row Count 11 (+ 4) % Row 4 \SetRowColor{LightBackground} \seqsplit{equals(map2)} & Compares this map with the specified map and returns true if both maps are equal; otherwise, returns false. \tn % Row Count 15 (+ 4) % Row 5 \SetRowColor{white} get(key) & Returns the value to which the specified key is mapped, or null if the map contains no value for this key. \tn % Row Count 19 (+ 4) % Row 6 \SetRowColor{LightBackground} isEmpty() & Returns true if the map has zero key-value pairs. \tn % Row Count 21 (+ 2) % Row 7 \SetRowColor{white} keySet() & Returns a set that contains all of the keys in the map. \tn % Row Count 23 (+ 2) % Row 8 \SetRowColor{LightBackground} put(key, value) & Associates the specified value with the specified key in the map. \tn % Row Count 26 (+ 3) % Row 9 \SetRowColor{white} \seqsplit{remove(key)} & Removes the mapping for the specified key from the map, if present, and returns the corresponding value. \tn % Row Count 30 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{x{0.99557 cm} x{2.43743 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Map Datatype (cont)}} \tn % Row 10 \SetRowColor{LightBackground} size() & Returns the number of key-value pairs in the map. \tn % Row Count 2 (+ 2) % Row 11 \SetRowColor{white} toString() & Returns the string representation of the map. \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Loop Statement}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{For Each Loop: \newline % Row Count 1 (+ 1) List\textless{}String\textgreater{} names = new List\textless{}String\textgreater{}\{'Alice', 'Bob', 'Charlie'\}; \newline % Row Count 3 (+ 2) for (String name : names) \{ \newline % Row Count 4 (+ 1) System.debug(name); \newline % Row Count 5 (+ 1) \} \newline % Row Count 6 (+ 1) Traditional For Loop: \newline % Row Count 7 (+ 1) for (Integer i = 0; i \textless{} 5; i++) \{ \newline % Row Count 8 (+ 1) System.debug(i); \newline % Row Count 9 (+ 1) \}% Row Count 10 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.06423 cm} x{2.36877 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Triggers - Context Variable}} \tn % Row 0 \SetRowColor{LightBackground} Trigger.new & Contains a list of newly created or updated records. \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Trigger.old & Contains a list of old records before they were updated. \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \seqsplit{Trigger.newMap} & Contains a mapping between IDs and objects for all new records. \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} \seqsplit{Trigger.oldMap} & Contains a mapping between IDs and objects for all old records. \tn % Row Count 11 (+ 3) % Row 4 \SetRowColor{LightBackground} \seqsplit{Trigger.isInsert} & Returns true if the trigger is running due to an Insert operation. \tn % Row Count 14 (+ 3) % Row 5 \SetRowColor{white} \seqsplit{Trigger.isUpdate} & Returns true if the trigger is running due to an Update operation. \tn % Row Count 17 (+ 3) % Row 6 \SetRowColor{LightBackground} \seqsplit{Trigger.isDelete} & Returns true if the trigger is running due to a Delete operation. \tn % Row Count 20 (+ 3) % Row 7 \SetRowColor{white} \seqsplit{Trigger.isBefore} & Returns true if the trigger is running before data is written to the database. \tn % Row Count 23 (+ 3) % Row 8 \SetRowColor{LightBackground} \seqsplit{Trigger.isAfter} & Returns true if the trigger is running after data is written to the database. \tn % Row Count 26 (+ 3) % Row 9 \SetRowColor{white} \seqsplit{Trigger.isUndelete} & Returns true if the trigger is running due to an Undelete operation. \tn % Row Count 29 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.30454 cm} x{2.12846 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{SOQL}} \tn % Row 0 \SetRowColor{LightBackground} SELECT Fields FROM Object & SELECT Field1, Field2 FROM ObjectName WHERE Condition \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} ORDER BY Clause & SELECT Name, CreatedDate FROM Account ORDER BY CreatedDate DESC \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} LIMIT Clause & SELECT Name FROM Account LIMIT 10 \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} GROUP BY Clause & SELECT Industry, COUNT(Id) FROM Account GROUP BY Industry \tn % Row Count 11 (+ 3) % Row 4 \SetRowColor{LightBackground} Aggregate Functions & SELECT AVG(Amount) FROM Opportunity \tn % Row Count 13 (+ 2) % Row 5 \SetRowColor{white} Relationship Queries & SELECT Name, (SELECT LastName FROM Contacts) FROM Account \tn % Row Count 16 (+ 3) % Row 6 \SetRowColor{LightBackground} Date Functions & SELECT Name FROM Account WHERE CreatedDate = THIS\_MONTH \tn % Row Count 19 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.51495 cm} x{2.91805 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Aggregate Functions}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{COUNT()} & Counts the number of records in the query result. \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} SUM() & Calculates the sum of a numerical field. \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} AVG() & Calculates the average value of a numerical field. \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} MIN() & Finds the minimum value of a numerical field. \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} MAX() & Finds the maximum value of a numerical field. \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.30454 cm} x{2.12846 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Date and time functions}} \tn % Row 0 \SetRowColor{LightBackground} TODAY & Returns the current date (excluding hours, minutes, seconds). \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} YESTERDAY & Returns the date of yesterday. \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} THIS\_MONTH & Returns all records created in the current month. \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} LAST\_N\_DAYS:n & Returns all records created in the last n days. \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} NEXT\_N\_DAYS:n & Returns all records that will be created in the next n days. \tn % Row Count 13 (+ 3) % Row 5 \SetRowColor{white} \seqsplit{CALENDAR\_MONTH(fieldName)} & Returns the month of a specific date field. \tn % Row Count 15 (+ 2) % Row 6 \SetRowColor{LightBackground} \seqsplit{DAY\_ONLY(fieldName)} & Returns the day of a specific date field \tn % Row Count 17 (+ 2) % Row 7 \SetRowColor{white} THIS\_YEAR & Returns all records created in the current year. \tn % Row Count 19 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}