Lynda Kane
@labboopanda
RPS: An Apex Map
Learning Journey
Knowledge Gaps
A knowledge gap
is a discrepancy
between what is
known and what
should be known
Example 1:
Lynda the Human GPS
Despite going to
Parmatown Mall
hundreds of times, I still
don’t know how to get
there!
Example 2:
Imaginary Numbers
Knowledge Gap + Imposter Syndrome =
😨 😱 😭 😕 😣 🤢 🤔 😰
My Apex Knowledge Gap
Confession:
If I have to review
code, I try to get
away with ignoring or
skipping over any
code that uses Map.
What I Know:
● Key - Value Pair
● Key is unique
● Often see/used
with triggers
● Common is id
with query
results
What I Want to
Know:
● How to create
● How to get the
data
● Can I actually
use one
successfully?
My Apex Map Learning Plan
● Rock, Paper, Scissors
● Screen flow for user to play the game with Apex Action(s)
● Apex to pick computer’s random weapon choice
● Apex to determine who won
● Apex to determine what action the weapon did to win (cut,
smash, cover)
● Test class
Apex Map
Notes:
● Keys and Values
can by ANY data
type (primitive,
collection, sObject,
user-defined, Apex
built-in)
● If key is a string, it
is case-sensitive
(Rock ≠ rock)
Constructor:
● Map<type, type>()
Methods:
● put(key, value) - add pairs
● get(key) - returns value for specified key
● keySet() - returns a Set of the keys (unique, unordered)
● values() - returns List of all values
● size() - # of pairs
● isEmpty() - check for no pairs
● containsKey(key) - is this key in the map? Boolean
● clear() - remove all pairs
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/a
pex_methods_system_map.htm
Rock, Paper, Scissors
Weapon This Wins Over: This Wins By:
Rock Scissors smashes
Paper Rock covers
Scissors Paper cuts
Map<String, List<String>>
Apex Actions in Flows (aka Surprises)
● Only 1 Method per Class can be invocable
● Parameters passed MUST be a List
● Return MUST be a List
Let’s Code
Code Recap
● Random Weapon Select - Map was overkill, use List
● Make the Weapons Map
● Get what chosen Weapon can beat
● Get how the chosen Weapon wins (action)
● Bring it all together
● Code Coverage
Screen Flow
Screen Flow Recap
● 1st Screen: User selects weapon from picklist
● Apex Action: run the code!
○ Pass in the User’s selection
○ Store the result
● 2nd Screen: Show the result
Lifelong Learning
● Error handling (what if user chose Spatula or Lizard as the
weapon?) (use containsKey(key))
● Use keySet() instead of List to randomly pick computer
weapon choice
● Add images to Flow (visual appeal)
● Improve code coverage
● Documentation
● LC or LWC instead for UI
What about Rock, Paper, Scissors, Lizard, Spock
● How to handle 2 possible weapons that can win over
selection (Map<String,List<String>>)
● How to get the action that wins (Map<List<String>,String>)
● Modify the Flow for additional choices
Questions/Comments?
Want to make this: Instructions
Contact:
Email: labboo.gc@gmail.com
Twitter: @labboopanda
LinkedIn: https://www.linkedin.com/in/lynda-kane-71379610/
Trailblazer.me: https://trailblazer.me/id/labboo

Rock, Paper, Scissors: An Apex Map Learning Journey

  • 1.
    Lynda Kane @labboopanda RPS: AnApex Map Learning Journey
  • 3.
    Knowledge Gaps A knowledgegap is a discrepancy between what is known and what should be known Example 1: Lynda the Human GPS Despite going to Parmatown Mall hundreds of times, I still don’t know how to get there! Example 2: Imaginary Numbers Knowledge Gap + Imposter Syndrome = 😨 😱 😭 😕 😣 🤢 🤔 😰
  • 4.
    My Apex KnowledgeGap Confession: If I have to review code, I try to get away with ignoring or skipping over any code that uses Map. What I Know: ● Key - Value Pair ● Key is unique ● Often see/used with triggers ● Common is id with query results What I Want to Know: ● How to create ● How to get the data ● Can I actually use one successfully?
  • 5.
    My Apex MapLearning Plan ● Rock, Paper, Scissors ● Screen flow for user to play the game with Apex Action(s) ● Apex to pick computer’s random weapon choice ● Apex to determine who won ● Apex to determine what action the weapon did to win (cut, smash, cover) ● Test class
  • 6.
    Apex Map Notes: ● Keysand Values can by ANY data type (primitive, collection, sObject, user-defined, Apex built-in) ● If key is a string, it is case-sensitive (Rock ≠ rock) Constructor: ● Map<type, type>() Methods: ● put(key, value) - add pairs ● get(key) - returns value for specified key ● keySet() - returns a Set of the keys (unique, unordered) ● values() - returns List of all values ● size() - # of pairs ● isEmpty() - check for no pairs ● containsKey(key) - is this key in the map? Boolean ● clear() - remove all pairs https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/a pex_methods_system_map.htm
  • 7.
    Rock, Paper, Scissors WeaponThis Wins Over: This Wins By: Rock Scissors smashes Paper Rock covers Scissors Paper cuts Map<String, List<String>>
  • 8.
    Apex Actions inFlows (aka Surprises) ● Only 1 Method per Class can be invocable ● Parameters passed MUST be a List ● Return MUST be a List
  • 9.
  • 10.
    Code Recap ● RandomWeapon Select - Map was overkill, use List ● Make the Weapons Map ● Get what chosen Weapon can beat ● Get how the chosen Weapon wins (action) ● Bring it all together ● Code Coverage
  • 11.
  • 12.
    Screen Flow Recap ●1st Screen: User selects weapon from picklist ● Apex Action: run the code! ○ Pass in the User’s selection ○ Store the result ● 2nd Screen: Show the result
  • 13.
    Lifelong Learning ● Errorhandling (what if user chose Spatula or Lizard as the weapon?) (use containsKey(key)) ● Use keySet() instead of List to randomly pick computer weapon choice ● Add images to Flow (visual appeal) ● Improve code coverage ● Documentation ● LC or LWC instead for UI
  • 14.
    What about Rock,Paper, Scissors, Lizard, Spock ● How to handle 2 possible weapons that can win over selection (Map<String,List<String>>) ● How to get the action that wins (Map<List<String>,String>) ● Modify the Flow for additional choices
  • 15.
    Questions/Comments? Want to makethis: Instructions Contact: Email: labboo.gc@gmail.com Twitter: @labboopanda LinkedIn: https://www.linkedin.com/in/lynda-kane-71379610/ Trailblazer.me: https://trailblazer.me/id/labboo